java.io.FileNotFoundException The system cannot find the path specified [closed]

寵の児 提交于 2019-12-13 10:07:10

问题


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..

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();
    }

回答1:


You have not provided the file name so you get that exception,use below code

  OutputStream file = new FileOutputStream(new File("D://timer.pdf"));

See the doc here




回答2:


You should provide a valid file name. You just can't provide the directory name alone, which is why you get the FileNotFoundException.

OutputStream file = new FileOutputStream(new File("D://someFile.txt"));


来源:https://stackoverflow.com/questions/19922504/java-io-filenotfoundexception-the-system-cannot-find-the-path-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!