Solved

Wirte files in jar

Posted on 2008-06-10
11
731 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
ID: 21754979
You can't write to a jar file
0
 
LVL 4

Author Comment

by:anmalaver
ID: 21755446
I would appreciate a more complete answer please...
0
 
LVL 92

Expert Comment

by:objects
ID: 21755697
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
ID: 21757014
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
ID: 21757301
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:CEHJ
ID: 21757968
>>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
ID: 21759996
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
ID: 21764577
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
ID: 21764978
Thanks, i'm gonna see that tomorrow.
0
 
LVL 4

Author Comment

by:anmalaver
ID: 21813986
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
ID: 31465928
Thanks a lot, i think i have to look for the way to sign it...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 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

14 Experts available now in Live!

Get 1:1 Help Now