简体   繁体   中英

create executable jar file with text file

I have a java project this project has a text file to read from. i want to export a excuteable jar file . i did it but when i run the program on cmd window it says that the file couldnt be found.

How to export the whole project inclusive the text file ? or should i place the file in another place

scn = new Scanner(new File("src/test.txt"));
    while(scn.hasNext())
    {
        String instructionLine = scn.next();
        li.add(instructionLine) ;

    }

    scn.close();

}
    catch(Exception e)
    {
        System.out.print("File couldnt found !");
    }

You need to use getResourceAsStream() to get data from within your jar file.

See this " prior answer on StackOverflow ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM