aspose file tools*
The moose likes Struts and the fly likes Accessing File from ActionClass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing File from ActionClass" Watch "Accessing File from ActionClass" New topic
Author

Accessing File from ActionClass

madhu Chitloore
Greenhorn

Joined: Jul 23, 2004
Posts: 11
Hi,
I need to access file which is above WEB-INF folder from my action class.
I dont want to specify the absolute path for this...
I even used URL url = new URL("http://localhost:7001/webapps/props/some.xml");
and "http://localhost:7001/" is also absolute ... can anyone tell me how to access the file ?

Thanks,
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Try something like,




This will get you the path and then do normal IO.
[ April 23, 2008: Message edited by: Anubhav Anand ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

Files above WEB-INF are inaccessible through the web server interface. It's this way by design, so malicious visitors can't get the source of your pages or Java classes.
I usually put files I need access to in WEB-INF/classes and load them with Class.getResourceAsStream().


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
madhu Chitloore
Greenhorn

Joined: Jul 23, 2004
Posts: 11
I think files like propertyfiles , xmls , etc.. should be above WEB-INF ...
Not every such files will be placed inside WEB-INF ... Anyway it worked ..

Thank you
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

Originally posted by madhu cm:
I think files like propertyfiles , xmls , etc.. should be above WEB-INF ...
Not every such files will be placed inside WEB-INF ... Anyway it worked ..

Thank you


Indeed they ought to be outside the WEB-INF folder. The way I suggested will anyway work for any kind of location be it in or outside WEB-INF. Moreover, the files inside WEB-INF are not accessible through web server interface. That's *my* take.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing File from ActionClass