Results 1 to 2 of 2
  1. #1
    Serrano0811 is offline Member
    Join Date
    Apr 2010
    Rep Power

    Default I can't read a text file located inside my jar.

    Hi, Im getting a hard time trying to read a text file
    inside my jar file, Im trying this way:

    private Scanner in;

    public void openFile() {
    try {
    in= new Scanner(new File("data.txt"));
    catch(FileNotFoundException fileNotFoundException) {
    System.err.println("The file cannot be found");

    Where "data.txt is in the root dir of my jar file(The file always exist inside the jar file), I know its easier to create a new text file where the jar is launch, but it lose portability, I want to move from place to place without losing the
    informacion contained inside de file(data.txt)

    Any idea guyz? :)
    thanks in advance
    Last edited by Serrano0811; 04-21-2010 at 05:56 PM. Reason: title should be more specific

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    A 'file' in a .jar file is not a file; it is just an entry in that .jar file and you can only read from that resource. Read the API documentation for the Class.getResourceAsStream( ... ) method.

    kind regards,


Similar Threads

  1. Replies: 2
    Last Post: 11-29-2009, 11:26 AM
  2. the check file inside of the zip in javascript
    By naval gupta in forum Advanced Java
    Replies: 1
    Last Post: 07-18-2009, 01:12 PM
  3. Access to resources inside jar file
    By aleks.farrier in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-15-2009, 02:29 PM
  4. search file inside Zip, Rar file
    By hungerToJava in forum New To Java
    Replies: 0
    Last Post: 03-21-2009, 09:36 AM
  5. Replies: 0
    Last Post: 02-11-2009, 10:53 AM

Posting Permissions

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