*
The moose likes Beginning Java and the fly likes writing back to jar file ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "writing back to jar file ??" Watch "writing back to jar file ??" New topic
Author

writing back to jar file ??

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello,
My question is:-
1. I have a jar file say "test.jar"
2. This jar file contains a file say abc.txt, which has been written using ObjectOutputStream and ObjectInputStream.
3. I have to give an option where when user clicks this option it will go to my server through URL connection and get some information again as an object format.
4. I have to update this String object into the abc.txt file of test.jar.
My question is How?
I tried exploring the JavaOutputStream class but could not able to understand how to use this... can you please help me..
Regards,
Arun
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I think maybe you are trying to make this too difficult. But I have to ask a question or 2.
Are you having a problem with basic I/O in JAVA or Is your problem with how to write to a file that exists inside a JAR file?
If the latter is true, then is your java program running from the same JAR file that the txt file exists? If this is true then just do your basic I/O for that file. A jar file is just a directory structure. So your applicaion will treat the files inside it just like any other file on the Hard Drive. For instance, if your JAR file is set up thusly:
classes/*.class
images/*.gif *.jpeg, etc
manafest
text/*.txt
Then you want to create a File object for a txt file:
File file = new File("/text/test.txt");
Now, if on the other hand your text files are contained outside of your app but still in a JAR file you will need to use a class Loader to get inside the JAR file and open them.
If you are having problems with Basic Java I/O I would suggest postsing some code you are using for your I/O operations and/or post a question in the Java I/O forum maybe.
Hope that helps a little.


GenRocket - Experts at Building Test Data
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks Gregg for your reply... I was trying with following codes but in vain. any other suggestion:-


Both the code snippet is giving me following error:
Error from update++++: java.io.FileNotFoundException: file:/E:/test/insta.jar!/m
odel.ins (The filename, directory name, or volume label syntax is incorrect)
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Any Thoughts for this...Perhaps there should be something like setResource in the API..I am asking too much...
regards,
Arun
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
I tried with another set of code for writing a file back into the jar file..but surprisingly it works as a regular file writing..what i mean to say it makes a file but outside of the jar file...
can somebody give me a lead? Perhaps Mr. bartender can lend me a helping hand for this :-)
regards,
Arun
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
I tried finding an answer for this question on every possible place and perhaps tried all possibilities...and my only hope is this forum...
And I therefore request all the people to please let me know where I am wrong...Am I doing something very foolishly somewhere?..Is there any workaround for it..Please help me, if possible.
regards,
arun
[ June 27, 2002: Message edited by: arun mahajan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing back to jar file ??
 
Similar Threads
java lib loading
create jar problem: jarFile.jar: no such file or directory
How to write contents in a ByteArrayOutputStream to a disk file?
writing to Text file.
File question from JQPlus