I have built a Java application that reads data from a txt file located in the src folder. The path I have specified in the program is /src/data.txt and it works when I run it from netbeans. However when I tried to open the jar file, nothing opens. So I tried using javac from command line and this gives me the error that data.txt can't be found.
How do I make sure that the data file is included in the jar so it will work as a standalone? Thanks. EDIT1 : Here is a snippet of the code I use to load the file. And the path used is the aforementioned /scr/data.txt
public String [] openFile() throws IOException { FileReader fr = new FileReader(this.path); BufferedReader br = new BufferedReader(fr); String []text = new String[this.numberoflines]; for(int i=0;i<this.numberoflines;++i) { text[i]=br.readLine(); } br.close(); return text; } EDIT2 : Well here is the tvf output:
Error: Could not find or load main class jar C:\Users\Abhishek>jar -tvf Scrades.jar 0 Sun Jan 22 18:47:08 IST 2012 META-INF/ 199 Sun Jan 22 18:47:06 IST 2012 META-INF/MANIFEST.MF 2562 Sun Jan 22 18:47:08 IST 2012 CombinationGenerator.class 684 Sun Jan 22 18:47:08 IST 2012 Gameplay$1.class 684 Sun Jan 22 18:47:08 IST 2012 Gameplay$2.class 684 Sun Jan 22 18:47:08 IST 2012 Gameplay$3.class 684 Sun Jan 22 18:47:08 IST 2012 Gameplay$4.class 684 Sun Jan 22 18:47:08 IST 2012 Gameplay$5.class 969 Sun Jan 22 18:47:08 IST 2012 Gameplay$6.class 18279 Sun Jan 22 18:47:08 IST 2012 Gameplay.class 2275 Sun Jan 22 18:47:08 IST 2012 PermutationGenerator.class 1252444 Sun Jan 22 18:47:08 IST 2012 eng_final1.txt 3771960 Sun Jan 22 18:47:08 IST 2012 english_huge.txt 815532 Sun Jan 22 18:47:08 IST 2012 english_long.txt 16104 Sun Jan 22 18:47:08 IST 2012 english_short.txt 1506 Sun Jan 22 18:47:08 IST 2012 readFile.class
jar -tvf the.jar.-tvf. After all, how could you copy/paste the output of the classes etc. to SO? Thetoption provides a listing that you can copy and paste to the site. Note that if you'd done as I specified and pasted the output, I'd now be in a position to answer your question to Mob.