0

重複の可能性:
Javaでファイルをコピーする標準的な簡潔な方法?

location のフォルダーに一連の .png ファイルがありますC:\Desktop\input\Acsady\dZI_3.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 関数が成功しなかったことを意味します。

4

2 に答える 2

0

This is extracted from java docs. May be helpful to you to find root cause.

Renames the file denoted by this abstract pathname. Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.

于 2012-11-08T16:20:28.273 に答える
0

Files.copyJava 1.7 を使用している場合は、こちらをご覧ください。

于 2012-11-08T16:16:11.033 に答える