Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Jar file to read text file from within itself

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Jar file to read text file from within itself

    Is there a way for a JAR file to read a text file (or any file for that matter) from within itself, no matter what platform? If so, how?


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    42
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Jar file to read text file from within itself

    Use the methot getResourceAsStream(), for example, the following code will read MyFile.txt from within the Jar file:

    MyClass.getResourceAsStream("com/mycompany/MyFile.txt");

    java exception
    Last edited by hns1984; January 11th, 2012 at 05:50 PM.

  3. The Following User Says Thank You to hns1984 For This Useful Post:

    KILL3RTACO (October 24th, 2011)

  4. #3
    Member
    Join Date
    Aug 2011
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Jar file to read text file from within itself

    +thanks this helps me alot

Similar Threads

  1. Read text file
    By cardamis in forum Java IDEs
    Replies: 2
    Last Post: November 4th, 2011, 11:59 PM
  2. How to read a text from an Image file?
    By GautamRy in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: October 5th, 2011, 05:02 AM
  3. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  4. Read a text file and parse the contents of file
    By HelloAll in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2011, 04:47 AM
  5. Read data from text file
    By yroll in forum Algorithms & Recursion
    Replies: 4
    Last Post: December 31st, 2009, 12:40 AM

Tags for this Thread