File.renameTo() fails

后端 未结 5 2163
半阙折子戏
半阙折子戏 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 18:52

    This is working fine for me. Rename is done using two steps but don't forget to set permissions in manifest.xml with:

    
    
    
    public boolean RenameFile(String from, String to) { 
      to.replace(" ", ""); // clear all spaces within file name
      File oldfile = new File(from);
      File newfile = new File(to);
      File tempfile = new File(to + ".tmp"); // add extension .tmp
      oldfile.renameTo(tempfile);
      return (tempfile.renameTo(newfile));
    }
    

提交回复
热议问题