aspose file tools*
The moose likes Servlets and the fly likes Accessing files that are there in classes directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing files that are there in classes directory" Watch "Accessing files that are there in classes directory" New topic
Author

Accessing files that are there in classes directory

Raghavender Ammagari
Greenhorn

Joined: Aug 11, 2008
Posts: 13
I have a properties file that is present in WEB-INF/classes...i could read that file as shown below



how to do a write process on the same file...the code till now is given below..please help me...
Raghavender Ammagari
Greenhorn

Joined: Aug 11, 2008
Posts: 13
Please do reply..had expected an immediate solution in coderanch
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Writing/modifying properties files at run-time sounds like trouble to me.
Particularly one that is part of a web application classpath.
There is a reason that you can only GET resources from the classLoader.

To answer your question on how you may be able to do it:

An alternative method to look at is the ServletContext method: getRealPath().
That converts a website relative path into a true location on disk.
so


Now you have the File handle, you can open it for writing.

However
- this may not actually resolve to a File on disk. It might be a file in a jar archive, which would not be editable.
- even if it is a file, and you write to it, there is no guarantee it will be read again except by restarting the web application.

What is the use case for this? Are these config properties intended to be edited often?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

I whole-heartedly agree with Stefan that this is a bad idea. WHat happens when you need to update and redeploy the app?

I always put read/write configuration in the DB where it is independent of the application itself.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing files that are there in classes directory