Solved

Wirte files in jar

Posted on 2008-06-10
11
719 Views
Last Modified: 2013-12-29
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
0
Comment
Question by:anmalaver
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You can't write to a jar file
0
 
LVL 4

Author Comment

by:anmalaver
Comment Utility
I would appreciate a more complete answer please...
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
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.

0
 
LVL 7

Expert Comment

by:humanonomics
Comment Utility
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.

0
 
LVL 13

Expert Comment

by:MicheleMarcon
Comment Utility
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

http://java.sun.com/docs/books/tutorial/deployment/jar/
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>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
0
 
LVL 4

Author Comment

by:anmalaver
Comment Utility
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.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
signing the jar should avoid that. And you'll have the same security problems whether you are writing to a jar or not.

0
 
LVL 4

Author Comment

by:anmalaver
Comment Utility
Thanks, i'm gonna see that tomorrow.
0
 
LVL 4

Author Comment

by:anmalaver
Comment Utility
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.
0
 
LVL 4

Author Closing Comment

by:anmalaver
Comment Utility
Thanks a lot, i think i have to look for the way to sign it...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now