2012-02-02 99 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