getClass().getResource(“/”) returns null in command line

后端 未结 2 770
死守一世寂寞
死守一世寂寞 2020-12-19 16:44

I\'m trying to read a file in my maven project at /src/main/resources/file.txt.

I\'m using

URL url=this.getClass().getResource(\"/\");
String filePa         


        
2条回答
  •  醉酒成梦
    2020-12-19 17:16

    You should move that file into your CLASSPATH and get it like this:

    InputStream is = this.getClass().getResourceAsStream("file.txt");
    

提交回复
热议问题