user616639 user616639 - 1 year ago 82
Java Question

delete and rename a file in java

i've created a file "file1" in java and i read that "file1" and made some changes to the data read from "file1" and i wrote the new data to another file "file2" what i need is to delete the previous file "file1" and change the name of the file "file2" to "file1"...
please somebody help me with this....

Answer Source
//rename file
File file = new File("oldname");
File file2 = new File("newname");
boolean success = file.renameTo(file2);

//delete file
File f = new File("fileToDelete");
boolean success = f.delete();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download