Making a small hangman game just for fun and to experiment more with IO. Original Solution was as the code shows which works in the IDE (Using Netbeans). Issue is that when i export it as a Jar file, it can't find the file I'm referencing. How do I correctly read from an external file once it's exported?
public HangmanGame(){
File file = new File("src\\hangman\\words");
try{
Scanner fileScan = new Scanner(file);
int number = (int)(Math.random()*260);
for(double i=0; i<260; i++){
if(i == number){
word = fileScan.nextLine();
fileScan.close();
break;
}else{
fileScan.nextLine();
}
}
}catch(FileNotFoundException e){
System.out.println(e.getMessage());
}
System.out.println(word);
}