这是我目前要删除的文件,但它无法正常工作.我认为这可能是许可问题或其他什么,但事实并非如此.我正在测试的文件是空的并且存在,所以不确定它为什么不删除它.
UserInput.prompt("Enter name of file to delete");
String name = UserInput.readString();
File file = new File("\\Files\\" + name + ".txt");
file.delete();
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
我现在有:
File file = new File(catName + ".txt");
String path = file.getCanonicalPath();
File filePath = new File(path);
filePath.delete();
Run Code Online (Sandbox Code Playgroud)
尝试在运行时找到正确的路径,以便在程序转移到另一台计算机时仍然可以找到该文件.