Results 1 to 4 of 4
  1. #1
    Arsenicmic is offline Member
    Join Date
    Aug 2009
    Location
    Bruxelles, Belgium
    Posts
    2
    Rep Power
    0

    Default Stream problem when I export my project in a .jar executable archive

    Hello everyone,
    My problem is that I have made a program that use Output and Input Streams for saving data in a file. While I try it in my IDE (NetBeans 6.7.1) everything works perfectly well. But when I try to use my .jar executable, my program works well but can't read nor write data’s!
    Have somebody an idea why it doesn't work ?
    Thanks for your answers

    P.S. I beg your indulgence for my English. I speak French and have never had any English course …the most English I learned is from javaDoc ;-)
    Last edited by Arsenicmic; 08-31-2009 at 05:50 PM.

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

    Default

    Mr. Poison:

    Your English is fine, so please don't worry about that.

    I am no expert in Applets but I do know that to read and write files from a host machine requires proper permissions (a "signed" applet). Question: must this application be an applet? Also, what do your I and O routines look like? Are you looking for the files in the correct locations? And what error messages do you get?

    Best of luck!

  3. #3
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Writting: You cannot easily write data to a jar file (though it can be done). If you write to a file it is easier to save it onto the host machine. If you want to know where that is:

    Java Code:
    File file = new File("");
    System.out.println(file.getAbsolutePath());

    Reading:

    You can open a data file in a jar but you must give the path of that data file otherwise it doesn't know where to look.

    You can derive the path by using an object's class information:

    Java Code:
    System.out.println(this.getClass().getResource("")); //see jar path for this class
    Java Code:
    File file = null;
    try
    {
       file = new File(this.getClass().getResource("resources/myFile.txt").toString()); //adjust the directory and file name can use ".." to back a directory if need be
    }
    catch(Exception e)
    {
       System.out.println("This File doesn't exist!");
    }
    My Hobby Project: LegacyClone

  4. #4
    Arsenicmic is offline Member
    Join Date
    Aug 2009
    Location
    Bruxelles, Belgium
    Posts
    2
    Rep Power
    0

    Default Thank you two

    Thanks, really!
    I didn't expect to get so quick answers. And I want to apologize for answering still now, because in fact, I did realize one or two day after that my problem was my own stupidity! The directory in witch I export my projects have been renamed (certainly a mistake of mine) so that I have been trying the same old version (in witch there was a problem of IO streams that I solved)!!!! And in the meantime, my corrected version was waiting me in a secret place of my computer!
    So I am truly sorry for wasting your time, and happily surprised of how quick you can get answers here. (It was my first post on a forum... for a first one, that's not a true success!)
    So thank you very much
    Arsenic Mic

Similar Threads

  1. Problem Jar executable files
    By Manfizy in forum New To Java
    Replies: 6
    Last Post: 08-13-2009, 01:15 PM
  2. Executable java project ..
    By xVent in forum Java Applets
    Replies: 5
    Last Post: 03-29-2009, 06:46 PM
  3. Problem in Export to Excel using Jexcel api
    By Padmalatha in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-19-2008, 08:09 AM
  4. Zip Archive Problem
    By satishbejgum in forum Advanced Java
    Replies: 1
    Last Post: 12-20-2007, 09:08 AM
  5. problem with the way to export data to CSV file
    By gonne in forum Java Servlet
    Replies: 0
    Last Post: 07-01-2007, 02:43 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
  •