java.io.FileNotFoundException 系统找不到指定的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19922504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.FileNotFoundException The system cannot find the path specified
提问by Adi
I have a timer set to invoke a class that contains pdf generating codes.I have set the file path where it needs to be saved..but it is showing exception as java.io.FileNotFoundException : D:\ (The system cannot find the path specified) .I dont know where is the mistake..
我有一个计时器设置来调用一个包含 pdf 生成代码的类。我已经设置了需要保存的文件路径..但它显示异常为 java.io.FileNotFoundException : D:\(系统找不到指定路径)。我不知道错误在哪里..
Here is my code..
这是我的代码..
try {
OutputStream file = new FileOutputStream(new File("D://"));
Document document = new Document();
//PDF generating code..
document.add(list); //In the new page we are going to add list
document.close();
file.close();
System.out.println("Pdf created successfully..");
} catch (Exception e) {
e.printStackTrace();
}
采纳答案by Shoaib Chikate
回答by SudoRahul
You should provide a valid file name. You just can't provide the directory name alone, which is why you get the FileNotFoundException
.
您应该提供一个有效的文件名。您不能单独提供目录名称,这就是为什么您获得FileNotFoundException
.
OutputStream file = new FileOutputStream(new File("D://someFile.txt"));