Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access files directly off server from Bean??

Status
Not open for further replies.

jaredgalen

Programmer
May 28, 2003
34
LT
I need to access a set of files (images) directly from the server using a java class.

Is this possible? Specifically, I take a directory name and get the list of files from that directory

if(location.exists())
{
if(location.isDirectory())
files = location.listFiles();
}
I have put the directory that I'm using in WEB-INF, classes, lib and with the jsp files but nothing works.
Is it possible to access a file\directoy directly off the server from a Java class?

Any help is greatly appreciated
jG
 
Are you using a fully qualified file/directory name like "/usr/local/aDir", or something like "aDir" ? Does the directory have to be within the webapp structure or is it outside the container structure ?

--------------------------------------------------
Free Database Connection Pooling Software
 
i used a name that would normally have directed the class to the folder if I was running locally and not in a server type application.

I don't know if should be inside or outside the webapp structure. Thats my main problem, I just don't know what to do.
 
Well, if the images directory is a resource used by other applications, not just your servlet container, then I would give a full path name. If not, just add it under your webapps root ("/") context and then get the real file location using ServletContext.getRealPath("/") (if you are in a JSP or servlet). If you are in a class, then I would pass in this path via a parameter.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top