java重命名文件,java怎麼重命名文件

本文目錄一覽:

IDEAjava文件重新命名

1.右鍵model 然後選擇refactor–rename—選擇rename module–ok

2.file– project structure–修改name為新model名

3.修改pom文件中舊項目名替換為新項目名

4.修改文件名,刷新項目OK

java中對文件怎麼重命名

file

f

=

new

file(“d:/aaa.txt”);//想命名的原文件

f.renameto(new

file(“d:/bbb.txt”));將原文件更改為bbb.txt,其中路徑是必要的

注意

java如何重命名一個文件

/**

* 修改文件名

* @param oldFilePath 原文件路徑

* @param newFileName 新文件名稱

* @param overriding 判斷標誌(如果存在相同名的文件是否覆蓋)

* @return

*/

public static boolean renameFile(String oldFilePath,String newFileName,boolean overriding){

File oldfile = new File(oldFilePath);

if(!oldfile.exists()){

return false;

}

String newFilepath = oldfile.getParent()+File.separator+newFileName;

File newFile = new File(newFilepath);

if(!newFile.exists()){

return oldfile.renameTo(newFile);

}else{

if(overriding){

newFile.delete();

return oldfile.renameTo(newFile);

}else{

return false;

}

}

}

原文鏈接:網頁鏈接

如有幫助請採納(不懂請提問),可以看我主頁,歡迎來交流學習;

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/151177.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-11-10 01:12
下一篇 2024-11-10 01:12

相關推薦

發表回復

登錄後才能評論