this.getClass().getClassLoader().getResourceAsStream always returning null

后端 未结 1 1281
别跟我提以往
别跟我提以往 2021-01-15 04:50

While reading a file in a web application with

this.getClass().getClassLoader().getResourceAsStream(../abc.txt)

is always returning null.

相关标签:
1条回答
  • 2021-01-15 04:55

    If your abc.txt is in classpath and in different package like com/test/oops/testpaper/abc.txt.

    Then read it like below.

    InputStream io=this.getClass().getClassLoader().getResourceAsStream("com/test/oops/testpaper/abc.txt");
    

    For detail please go through java doc.

    0 讨论(0)
提交回复
热议问题