无法在 Java 中删除文件
无论出于何种原因,我对 File.delete() 和 File.renameto(File) 遇到问题。例如:
private void doWork(){
File inputFile = new File("resources/custom/inputFile.txt");
System.out.println(inputFile.delete());
}
这对我来说返回 false 并且不会删除文件。
我没有在其他地方打开或使用此文件,我不明白为什么无法删除它。还有其他人遇到过这个问题或者对这个问题有任何见解吗?
For whatever reason I am having an issue with File.delete() and File.renameto(File). For example:
private void doWork(){
File inputFile = new File("resources/custom/inputFile.txt");
System.out.println(inputFile.delete());
}
This returns false for me and does not delete the file.
I don't have this file opened or in use anywhere else and I don't understand why I can't delete it. Has anyone else encountered this or have any insight into the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加一行:
这将打印实际路径(从根开始),并可能显示它不是您期望的路径。
Try adding a line:
This will print the actual path (starting from the root) and maybe reveal that it isn't the path you're expecting.
也试试这个,
如果你添加 try 和 catch 会有帮助
try this
also it will help if you add try and catch