File tempFile = new File(fw.getAbsolutePath() + ".tmp");
BufferedReader br = new BufferedReader(new FileReader(fw));
PrintWriter p = new PrintWriter(new FileWriter(tempFile));
String serData=(String)loadService().elementAt(i);
StringTokenizer st = new StringTokenizer(serData, ":");
String code=st.nextToken();
String name=st.nextToken();
if (!name.trim().equals(deleteString)) {
p.println(st);
p.flush();
}
p.close();
br.close();
if (!fw.delete()) {
System.out.println("Could not delete file");
return;
}
//Rename the new file to the filename the original file had.
if (!tempFile.renameTo(fw)){
System.out.println("Could not rename file");
}
I want to delete the file and rewrite is but can't. Can u tell me what is wrong with it??