Results 1 to 2 of 2
- 01-18-2011, 02:29 AM #1Member
- Join Date
- Jan 2011
- Rep Power
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.
So...how 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.
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.
- By bitse in forum Java AppletsReplies: 0Last Post: 12-09-2010, 05:56 PM
- By keneid in forum New To JavaReplies: 2Last Post: 06-14-2010, 10:18 AM
- By Rohaan in forum EclipseReplies: 9Last Post: 02-13-2010, 02:20 AM
- By nicedad in forum JDBCReplies: 8Last Post: 11-06-2009, 06:52 AM
- By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM