Two Laptop Bag*
The moose likes Java in General and the fly likes Problem with properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with properties file" Watch "Problem with properties file" New topic
Author

Problem with properties file

Neha Kathuriaa
Greenhorn

Joined: Sep 16, 2008
Posts: 25
Hi
I want to know .How do we find out the unused entries in a properties file and later remove them. Any idea
Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Define "unused". Not used by your application? And what if another application uses those properties?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Neha Kathuriaa
Greenhorn

Joined: Sep 16, 2008
Posts: 25
Those which are unused by any application.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

That's going to be hard, and I doubt it can be done automatically.

You first would have to find all Properties objects that load from that properties file (already quite hard - sometimes the properties file can be relative, otherwise absolute). Then you have to find all calls to getProperty on those objects and retrieve the property name from those calls. And that for all applications that can potentially use the file.


Now, if it's just one application, and one point of reading the file, you can choose to rebuild the Properties objects at that point. Strip away all properties you don't plan on using:

Afterwards the Properties object only contains the properties you are using (provided isUsedKeyForMyApplication is implemented properly), and when you store it again the file will only contain the properties you want.


Of course it is a LOT more difficult to do if there really are multiple applications reading the file, or multiple points at which the file is read (although the latter can be handled by a single method call).
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

There's no way of really ever knowing this. All you can do is scan your source code to see what properties they reference. Mind you there are binaries/programs that could be referencing properties and you wouldn't necessarily know it. But I assume you are talking about properties for your application only here.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
Don't get me started about those stupid light bulbs.
 
subject: Problem with properties file
 
Similar Threads
Common resource for all configurable parameters.
Replace words in a file by reading a properties file
How not to hard-code file location in java?
JAD File size
can the state of a checkbox be saved