【问题标题】:java.io.FileNotFoundException The system cannot find the path specified [closed]java.io.FileNotFoundException 系统找不到指定的路径[关闭]
【发布时间】:2013-11-24 04:59:38
【问题描述】:

我设置了一个计时器来调用一个包含 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();
    }

【问题讨论】:

  • 文件名在哪里?? (new File("D://")) 也应该有文件名

标签: java io file-handling


【解决方案1】:

您应该提供一个有效的文件名。您无法单独提供目录名称,这就是您获得 FileNotFoundException 的原因。

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

【讨论】:

    【解决方案2】:

    你没有提供文件名所以你得到那个异常,使用下面的代码

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

    请参阅文档here

    【讨论】:

      猜你喜欢
      • 2014-01-11
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2019-10-15
      • 2012-05-28
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多