在java中删除和重命名一个文件 [英] delete and rename a file in java
本文介绍了在java中删除和重命名一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请有人帮助我这个....
//重命名文件
File file = new File(oldname);
文件file2 =新文件(newname);
布尔成功= file.renameTo(file2);
//删除文件
文件f = new File(fileToDelete);
布尔成功= f.delete();
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....
解决方案
//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();
这篇关于在java中删除和重命名一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文