-5

我设置了一个计时器来调用包含 pdf 生成代码的类。我已经设置了需要保存它的文件路径..但​​它显示异常为 java.io.FileNotFoundException : D:\ (系统找不到指定的路径)。我不知道错误在哪里..

这是我的代码..

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

2 回答 2

3

您应该提供一个有效的文件名。您不能单独提供目录名称,这就是您获得FileNotFoundException.

OutputStream file = new FileOutputStream(new File("D://someFile.txt"));
于 2013-11-12T06:38:48.007 回答
2

您没有提供文件名,因此您得到了该异常,请使用以下代码

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

请参阅此处的文档

于 2013-11-12T06:39:08.713 回答