繁体   English   中英

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

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

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

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

文件已成功写入。

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

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

 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? 还是我的网址错误?

首先尝试简单的情况:

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

...

File pdfFile = new File(retrieve());

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

暂无
暂无

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

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