简体   繁体   English

可以从Tomcat Temp文件夹中读取文件

[英]Can a read a file from Tomcat Temp folder

I am reading byte data and writing a pdf file to my tomcat temp folder 我正在读取字节数据并将pdf文件写入tomcat临时文件夹

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

The file is written successfully. 文件已成功写入。

In a later stage on my application I need to be able to read that file. 在我的应用程序的稍后阶段,我需要能够读取该文件。 Can I read any file directly from temp folder? 我可以直接从temp文件夹读取任何文件吗? I am not able to 我不能

I am using the below path to refer that file while reading. 我正在使用以下路径在阅读时引用该文件。

 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.

Using this url I see blank result. 使用此网址,我看到空白的结果。 I assume there is another way to read urls from temp folder? 我认为还有另一种方法可以从临时文件夹中读取URL? Or is my url wrong? 还是我的网址错误?

First try the simple case: 首先尝试简单的情况:

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

... ...

File pdfFile = new File(retrieve());

If that works, you might try pdfFile.toURI() . 如果pdfFile.toURI() ,您可以尝试pdfFile.toURI() Probably something like file://C:/... (just 2 or 1 slashes). 可能类似于file://C:/... (仅2或1个斜杠)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM