File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to acess file outside a War file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to acess file outside a War file." Watch "How to acess file outside a War file." New topic

How to acess file outside a War file.

Hasif Subair

Joined: Aug 12, 2009
Posts: 24

When users upload images, I am saving it to an external folder(outside deployed WAR file). I need some way by which i can access these files and display it on the webpage. How can this be done.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 171

The user uploaded files can be displayed in a web page using servlet/jsp by reading the physical file (FileReader etc). Then the bytes of the read stream can be written into the output stream of servlet to display the read files in web page.

BufferedReader in = new BufferedReader(new FileReader("absoulte path name"));

No pain, No gain.
OCJP 1.6, Liferay Certified Developer 6.1
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Just be sure to release the file after you read it. Or your app will have a lot of memory problems.

[] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
I agree. Here's the link:
subject: How to acess file outside a War file.
It's not a secret anymore!