2012-02-02 50 views
1

我读字节的数据,写一个PDF文件到我的tomcat的temp文件夹可以读取从Tomcat Temp文件夹

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我看到空白结果。我认为有另一种方式来读取临时文件夹中的URL?或者是我的网址错了?

回答

3

首先尝试的简单情况:

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斜线)。

+0

什么是存储和检索方法? – 2012-02-02 09:44:26

+0

伪代码,不知何故必须传递生成的文件名。 – 2012-02-02 14:21:24