File.renameTo() fails

后端 未结 5 2167
半阙折子戏
半阙折子戏 2020-12-06 18:24

I have eclipse plugin jface application. A thread writes file via BufferedWriter. After writing is done I close the buffer after that I try to rename the file.

But

5条回答
  •  天涯浪人
    2020-12-06 18:58

    You can also do something like below:

    File o=new File("oldFile.txt");
    File n=new File("newFile.txt");
    n.delete();
    o.renameTo(n);
    

    n.delete() : We need to delete the file(new.txt) if exists.

    o.rename(n) : so that the file(old.txt) is renamed as new.txt

    How to find out why renameTo() failed?

    Reliable File.renameTo() alternative on Windows?

    http://www.bigsoft.co.uk/blog/index.php/2010/02/02/file-renameto-always-fails-on-windows

提交回复
热议问题