Results 1 to 5 of 5
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default Write to a file in a jar

    Hi

    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

    Java Code:
     FileOutputStream fos=new FileOutputStream("src/filename.ext");
               myop=new PrintStream(fos);
    above code would create a file in the src folder with filename.ext specified.
    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.

    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  4. #4
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    In general, I think that the answer is, "you don't". For one, jars don't hold files but resources
    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??

    i am sorry if i didnt get what you were trying to tell..but can you plz explain me more clearly...

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

Similar Threads

  1. how to write onto a file
    By mirage_87 in forum New To Java
    Replies: 6
    Last Post: 09-08-2009, 03:54 PM
  2. Replies: 5
    Last Post: 02-05-2009, 10:28 AM
  3. [SOLVED] File Write in File
    By Eku in forum New To Java
    Replies: 4
    Last Post: 10-27-2008, 04:01 AM
  4. write nio.CharBuffer to file
    By Beju in forum New To Java
    Replies: 5
    Last Post: 10-19-2008, 08:20 PM
  5. Write to file
    By esadeghi in forum Advanced Java
    Replies: 1
    Last Post: 05-21-2008, 01:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •