Java 在Windows 8中使用renameTo()重命名文件失败

Java 在Windows 8中使用renameTo()重命名文件失败,java,windows-8,rename,Java,Windows 8,Rename,我正在写一个小程序来获取我的音乐文件的订单(使用Win8)。我正在使用的一个类在需要时重命名一个文件,用零填充曲目编号。脚本可以更改名称,但不会重命名文件。它不会抛出错误,只是不会重命名文件 不工作的钻头: String newTrackkName = item.replace(oldFileName, newFileName); File oldFile = new File(oldFileName); Boolean renamed = oldFile.rename

我正在写一个小程序来获取我的音乐文件的订单(使用Win8)。我正在使用的一个类在需要时重命名一个文件,用零填充曲目编号。脚本可以更改名称,但不会重命名文件。它不会抛出错误,只是不会重命名文件

不工作的钻头:

    String newTrackkName = item.replace(oldFileName, newFileName);
    File oldFile = new File(oldFileName);

    Boolean renamed = oldFile.renameTo(new File(newFileName));

    System.out.println("\nthe file '" + item + "'" + ((!renamed) ? "\n\tHas NOT been renamed '" : "\n\tHas been renamed '") + newTrackkName + "'");
以下是println输出的示例:

the file 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\14 - Livin For You.mp3'
    Has NOT been renamed 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\14 - Livin For You.mp3'

the file 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\2 - Call Me (Come Back Home).mp3'
    Has NOT been renamed 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\02 - Call Me (Come Back Home).mp3'

the file 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\3 - I'm Still In Love With You.mp3'
    Has NOT been renamed 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\03 - I'm Still In Love With You.mp3'

the file 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\4 - Here I Am (Come And Take Me).mp3'
    Has NOT been renamed 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\04 - Here I Am (Come And Take Me).mp3'

the file 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\5 - How Can You Mend A Broken Heart.mp3'
   Has NOT been renamed 'c:\test\Al Green\Compact Command Performances_ 14 Greatest Hits\05 - How Can You Mend A Broken Heart.mp3'
至少它没有在重命名方面对我撒谎:-)


任何好的建议,我都尝试过使用Files.move选项,但也不起作用。

不要使用那个古老的API,使用NIO。将通过例外情况告诉你出了什么问题。@Holger说了什么。你可以在这里读到更多关于它的信息,谢谢,我会再试一次。