私は次のコードを持っていますが、それは機能していないようです..誰かがなぜ何か考えを持っていますか?基本的に、削除しようとしている2つの文字列を含む行を除くすべての行を含む新しいファイルを作成していますが、コードが機能していないようです。
public void removelines(String name, String email){
try{
//Create objects for our file and the temp file.
File f = new File("addy");
File temp = new File(f.getAbsolutePath()+ "temp");
//Our readers.
BufferedReader buf = new BufferedReader(new FileReader("addy"));
PrintWriter print = new PrintWriter(new FileWriter(temp));
String line = null;
while ((line = buf.readLine()) != null) {
//put all data not equal to that to be removed into the new file.
if(!line.trim().equals(name) || !line.trim().equals(email)){
print.println(line);
print.flush();
}
}
print.close();
buf.close();
f.delete();
temp.renameTo(f);
} catch (Exception e){
JOptionPane.showMessageDialog(null, "ERROR:" + e );
}
}