user1320716
user1320716

Reputation: 170

Java Eclipse--.txt File Not Found When Exported To .jar

So I've created a game, runs perfectly in eclipse--all of the images load and it reads properly from a text file. The text file provides level info. This is where my problem comes in. I exported it all to an executable .jar file, and it found all of the images. But it did not find the .txt file. Where does the .txt file need to be for it to be found?

    try{
        controlBoard = new Scanner(new FileInputStream("lvl1.txt"));
    }catch(Exception e){
        gb.error = true;
    }

Upvotes: 4

Views: 858

Answers (1)

duffymo
duffymo

Reputation: 308998

You should not access that file using FileInputStream. Get an InputStream using the class loader and getResourceAsStream(). It'll find it in the JAR.

Upvotes: 6

Related Questions