Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete and rename a file in java

Tags:

java

file

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"...now 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....

like image 450
user616639 Avatar asked Mar 19 '11 12:03

user616639


1 Answers

//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();
like image 113
lukastymo Avatar answered Oct 11 '22 12:10

lukastymo