getResourceAsStream returns null

前端 未结 16 2309
臣服心动
臣服心动 2020-11-22 04:00

I\'m loading a text file from within a package in a compiled JAR of my Java project. The relevant directory structure is as follows:

/src/initialization/Life         


        
16条回答
  •  广开言路
    2020-11-22 04:36

    You might want to try this to get the stream i.e first get the url and then open it as stream.

    URL url = getClass().getResource("/initialization/Lifepaths.txt"); 
    InputStream strm = url.openStream(); 
    

    I once had a similar question: Reading txt file from jar fails but reading image works

提交回复
热议问题