【问题标题】:Can a read a file from Tomcat Temp folder可以从 Tomcat Temp 文件夹中读取文件吗
【发布时间】:2012-02-02 05:43:50
【问题描述】:

我正在读取字节数据并将 pdf 文件写入我的 tomcat 临时文件夹

  FileOutputStream fos = new FileOutputStream(File.createTempFile("dummy-file", ".pdf"));

文件写入成功。

在我的应用程序的稍后阶段,我需要能够读取该文件。我可以直接从临时文件夹中读取任何文件吗?我做不到

我在阅读时使用以下路径来引用该文件。

 file:///C:/liferay-developer-studio-1.3.1/Tools/Liferay%20Developer%20Studio/liferay-portal-6.0-ee-sp2/tomcat-6.0.32/temp/dummy-file68824607895269300.pdf  //these numbers are string generated randomly while writing the file.

使用此网址我看到空白结果。我假设还有另一种方法可以从临时文件夹中读取 url?还是我的网址错了?

【问题讨论】:

    标签: java tomcat


    【解决方案1】:

    先试试简单的案例:

    File pdfFile = File.createTempFile("dummy-file", ".pdf"));
    FileOutputStream fos = new FileOutputStream(pdfFile);
    store(pdfFile.getPath());
    

    ...

    File pdfFile = new File(retrieve());
    

    如果可行,您可以尝试pdfFile.toURI()。 可能类似于 file://C:/...(只有 2 或 1 个斜线)。

    【讨论】:

    • 什么是存储和检索方法?
    • 伪代码,必须以某种方式传达生成的文件名。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2019-02-27
    • 2022-08-13
    相关资源
    最近更新 更多