如何从现有文件中读取并且如果包含特定字符串..i想从该文件中删除该行。如何在java中执行此操作?如果文件包含:
111
222
333
如果我接受输入222,它将删除222,文件将如下:
111
333
代码:
File ef = new File("Employee_info.txt");
File tf = new File("temp.txt");
FileReader fr = new FileReader(ef);
BufferedReader br =new BufferedReader(fr);
FileWriter fw = new FileWriter(tf);
BufferedWriter bw =new BufferedWriter(fw);
String line;
while((line=br.readLine())!=null)
{
if(line.contains(del_id)) continue;
bw.write(line);
bw.newLine();
}
bw.close();
fw.close();
br.close();
fr.close();`