可能重複:
Standard concise way to copy a file in Java?如何在Java中的不同位置創建一個文件的副本?
我有一組在位置C:\Desktop\input\Acsady\dZI_3.png
文件夾中的.png文件中。現在,我想使圖像的複製到其他位置C:\Desktop\input\final\Acsady\5_dZI_3.png
。 我該如何去做呢?我目前有以下代碼,它不會給我預期的結果。
String newName = outdir + File.separator + "final" + File.separator + nfname;
File newfname = new File(outdir + File.separator + "final" + File.separator + nfname);
String source = outdir + File.separator + lkupfname;
String target = outdir + File.separator + "final" + File.separator + nfname;
System.out.println("Copying file: "+source +" to "+target);
boolean status = filename.renameTo(newfname);
System.out.println("status : "+status);
我每次都得到狀態爲false,這意味着renameTo函數不成功。