以下内容给了我一个FileNotFoundException:无效的文件路径
String fileName = "folder/file" + "." + this.ext;
try {
File file = new File(fileName);
} catch(Exception e){
}
this.ext 之前已设置为 "txt"
经过尝试,我发现这工作得很好。
String ext = "txt";
String fileName = "folder/file" + "." + ext;
try {
File file = new File(fileName);
} catch(Exception e){
}
为什么我不能使用字段?
最佳答案
您没有理由不能使用字段,即 this.ext
。如果您将调试点放在以下行,您会发现 this.ext
未设置为 "txt"
String fileName = "folder/file" + "." + this.ext;
如果您不熟悉调试器,只需将以下行放在上面的行之前,您就可以找到问题:
System.out.println("this.ext="+this.ext);
关于java - 文件路径无效,但仅当我使用字段构建文件名时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58421041/