| Author |
Reading Properties File by One Jar from Another
|
Dennis Putnam
Ranch Hand
Joined: Feb 03, 2012
Posts: 208
|
|
|
I have 2 jar files (A and B) where A is an obsolete version and B is the new version of my app. To do the "update" all I need is to obtain the properties from A. How can I programatically read A's properties from B? When I search for examples of this I can only find JarInJar situations rather than external jars. TIA.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
You can access A jar content with ZipInputStream as:
|
The quieter you are, the more you are able to hear.
|
 |
Dennis Putnam
Ranch Hand
Joined: Feb 03, 2012
Posts: 208
|
|
|
Perfect. I will give it a try. Thanks.
|
 |
Dennis Putnam
Ranch Hand
Joined: Feb 03, 2012
Posts: 208
|
|
This is not doing what I expected in that it is not traversing directories. I have exactly 2 directories at the top level of the jar: KCBSEvents and META-INF. However, the only one it finds is META-INF. The main directory is not showing up. Here is my class:
How do I drill down to the file I need. It is in 'KCBSEvents/resources'? I don't think the way I am setting up BufferedReader is right either but I haven't gotten that far yet. TIA.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
That else block (33 - 35) shouldn't be there. What you did actually is this: get the first entry from the jar, and if it's not what I'm looking for, exit application.
Edit: I hope you don't plan to handle your exceptions by exiting application. Suppose this is just a testing version.
|
 |
Dennis Putnam
Ranch Hand
Joined: Feb 03, 2012
Posts: 208
|
|
DOH! How dumb is that? Yes this is a work in progress. I'll clean up all the exception handling when I have it working.
Can you also tell me how to set up the BufferedReader for my file? I can't seem to get anything that results in an inputStreamReader.
Thanks.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
Once you are in that while loop and you find the file you want to read:
Don't forget to close those input streams you are using (I think you omitted inputStream.close() after while loop). Or use try-with-resources instead.
|
 |
Dennis Putnam
Ranch Hand
Joined: Feb 03, 2012
Posts: 208
|
|
Sheesh, that was too easy. No wonder I couldn't find it. Thanks.
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
|
You're welcome.
|
 |
 |
|
|
subject: Reading Properties File by One Jar from Another
|
|
|