Results 1 to 2 of 2
  1. #1
    raindog308 is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default Using a text file in Eclipse...I'm confused

    I am working on an app that has a large amount of static content - thousands of lines of data. My plan is to ultimately distribute a .jar that would include a file that contains this data (as text, XML, etc.) Some classes in the app read through this data and use it. do I access this file within Java? It's not a FileReader operation (I don't think) because it's "in the jar" not "on the filesystem".

    Also, within Eclipse, as I'm working on the code, is there a way I can define it as a "will be in the jar" file in the Project? The file is defined in a subfolder in my src tree, but my attempts to access it haven't been successful.

    If someone can recommend a breadcrumb trail, I can read up - I'm just asking what the best way to do that is.

    Do I want to create an Ant task to create the jar every time I run tests or build? I'm using JUnit heavily for testing, so hopefully when I "Run As JUnit," that would work, too.


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    You are smart to ask these questions and are quite right -- there aren't "files" in a jar. You could get access to the text via an InputStream, and this can be obtained via the Class method getResourceAsStream. A Scanner object can read the text easily, as can an InputStreamReader which you'd likely wrap in a BufferedStreamReader.

Similar Threads

  1. Replies: 0
    Last Post: 12-09-2010, 05:56 PM
  2. Replies: 2
    Last Post: 06-14-2010, 10:18 AM
  3. Read text file with eclipse
    By Rohaan in forum Eclipse
    Replies: 9
    Last Post: 02-13-2010, 02:20 AM
  4. Replies: 8
    Last Post: 11-06-2009, 06:52 AM
  5. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 04:04 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