• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Accessing files that are there in classes directory

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do reply..had expected an immediate solution in coderanch
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic