Wirte files in jar

Hi people!

I'm working on a J2ME project, reading a file from same jar using getResourceAsStream from ClassLoader; I need to write some data on this file after. How can i do this?

Thanks a lot
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can't write to a jar file
anmalaverAuthor Commented:
I would appreciate a more complete answer please...
Mick BarryJava DeveloperCommented:
What you need to do is write to a file (say in the users home directory).
Then have your code first attempt to read from that file, if the file does not exist then fall back to what you currently do and read the file (affectively the defaults) from the jar.
Alternatively copy the file out of the jar (if hasn't already nbeen done) on startup.

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

One cannot write directly into the file which are present in jar, if you donot wish to make a copy of the file outside of the jar, you need to pull the file out in a temporary location, perform the write operation and then replace it again back in the jar file.

You can't write the "executable jar" you are running, because the file is in use.

You can, however, write to another jar file.

Remember that jar is an archive: it is a container for files.

You need to write the files first, then pack these files on the jar archive

>>I would appreciate a more complete answer please...

Sorry - something came up. Can you tell us why you want to write to a jar, then we could possibly come up with a  workaround
anmalaverAuthor Commented:
Thanks for all your answers.!

The point is:

My app is J2ME. I have a fle inside my jar that i can easily read, but I need to download some info and update this file. It will be great if I could write my jar, because, if i write something at any root, the mobile asks the user to allow the write for each byte...

Could i avoid this permission from the user?
What else can i do?

Thanks a lot again.
Mick BarryJava DeveloperCommented:
signing the jar should avoid that. And you'll have the same security problems whether you are writing to a jar or not.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anmalaverAuthor Commented:
Thanks, i'm gonna see that tomorrow.
anmalaverAuthor Commented:
Hi again

I've seen Java verified program http://www.javaverified.com/ to sign jars, but, is there another way to do this?, i want to distribute a beta version of my app, but i think it will be late if i send my application and wait...

Thanks a lot.
anmalaverAuthor Commented:
Thanks a lot, i think i have to look for the way to sign it...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.