【发布时间】:2019-10-16 20:13:14
【问题描述】:
下面给我一个FileNotFoundException: Invalid file path
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){
}
为什么我不能使用字段?
【问题讨论】:
-
你能粘贴整个类的代码吗?
-
您应该使用
Path实例而不是String来表示目录路径。
标签: java file field filenotfoundexception