62,636
社区成员




public class JavaSeTest {
public static void main(String[] args) {
JavaSeTest test = new JavaSeTest();
List<String> list;
try {
list = test.readFile("E:\\test.txt","CompletionScore1/192.168.0.101");
test.writeFile("E:\\test.txt", list);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private List<String> readFile(String filePath, String str)throws IOException {
File file = new File(filePath);
BufferedReader reader = null;
List<String> list = new ArrayList<String>();
reader = new BufferedReader(new FileReader(file));
String text = reader.readLine();
while (text != null) {
if (!text.trim().equals(str)) {
list.add(text + "\r\n");
}
text = reader.readLine();
}
reader.close();
return list;
}
private void writeFile(String filePath, List<String> list)
throws IOException {
File file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream outputStream = new FileOutputStream(file);
for (String s : list) {
outputStream.write(s.getBytes());
}
outputStream.close();
}
}