Write to a file in a jar
I am creating an application.In order to run the application i have to create jar files,which i do with the help of eclipse.I am developing the appl using eclipse.
I know how to write to a file using eclipse
above code would create a file in the src folder with filename.ext specified.
FileOutputStream fos=new FileOutputStream("src/filename.ext");
But what i want to know is how do i create and write to a file in a jar file..
Hope I am explaning it clearly..
any help would be appreciated.
In general, I think that the answer is, "you don't". For one, jars don't hold files but resources, or for a second, I believe that they're not in general supposed to be altered -- but there could be exceptions.
To make a jar using eclipse, select "Export" when right-clicking on your project.
To make a jar using Java, first consider if it's necessary as Fubarable says, and if so use the java.util.jar package.
I create jar files using eclipse export and have my jar files in such a way that the resources folder have files from which the application reads and does jobs...if reading can be done,is it not possible to write files to the resources folder of the jar??
Originally Posted by Fubarable
i am sorry if i didnt get what you were trying to tell..but can you plz explain me more clearly...
The general rule is that you can't do what you are trying to do. If you feel you must, then you're program will have to un-jar the jar file, find the text file, change it, and then re-jar the jar file. I don't think that it's worth this trouble. I suggest you look for some other way to do what you want that does not involve attempting to write to a file held within a Jar file.