Reading a text file from a jar

前端 未结 3 919
慢半拍i
慢半拍i 2020-12-07 06:07

I\'m having trouble reading a text file from inside a jar. I managed it while it was unzipped but now that I\'ve archived it it won\'t work. The jar has:

  • BTA.j
3条回答
  •  甜味超标
    2020-12-07 06:20

    Assuming you're executing the BTA.jar, you can use

    InputStream in = YourClass.class.getResourceAsStream("/Splash.txt");
    

    to retrieve an InputStream and pass it to the BufferedReader through an InputStreamReader.

    The rules for the format of the path to pass to the method are defined here, in the javadoc for the Class class.

提交回复
热议问题