I am trying to include a text file in the jar, and am using this code:
InputStream wordList = Dictionary.class.getResourceAsStream("words.txt");
try {
try (BufferedReader br = new BufferedReader(new InputStreamReader(wordList))) {
String line;
while((line = br.readLine()) != null){
this.words.add(line);
}
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Dictionary.class.getName()).log(Level.SEVERE, null, ex);
}
I am using NetBeans and there don't appear to be any suntax errors, and when I clean and build, I get this in the console:
ant -f "C:\\Users\\James\\OneDrive\\Documents\\NetBeans Projects\\WordFinder" -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\built-clean.properties
Deleting directory C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build
clean:
init:
deps-jar:
Created dir: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build
Updating property file: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\built-jar.properties
Created dir: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\classes
Created dir: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\empty
Created dir: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\generated-sources\ap-source-output
Compiling 3 source files to C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\classes
Note: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\src\wordfinder\ui\WordFinderUI.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 2 files to C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build\classes
compile:
Created dir: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\dist
Copying 1 file to C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\build
Nothing to copy.
Building jar: C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\dist\WordFinder.jar
To run this application from the command line without Ant, try:
java -jar "C:\Users\James\OneDrive\Documents\NetBeans Projects\WordFinder\dist\WordFinder.jar"
jar:
BUILD SUCCESSFUL (total time: 0 seconds)
There doesn't appear to be anything wrong when building the jar, since it says it was successful. Yet, when I try to run the jar, the UI and everything loads fine, but when I try to do something, the text file still isn't working because nothing happens, for example, when I click a button (The code reads from the text file when the button is clicked).
Is there anything I'm doing wrong?
Aucun commentaire:
Enregistrer un commentaire