getResourceAsStream returns null

前端 未结 16 2310
臣服心动
臣服心动 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:30

    What worked for me was to add the file under My Project/Java Resources/src and then use

    this.getClass().getClassLoader().getResourceAsStream("myfile.txt");
    

    I didn't need to explicitly add this file to the path (adding it to /src does that apparently)

提交回复
热议问题