FileNotFoundException in src/main/resources

后端 未结 4 662
梦如初夏
梦如初夏 2020-12-16 11:48

i placed a file in my maven project under src/main/resources the files name is simply temp.txt.

When i try to open the file:

BufferedReader br = new          


        
4条回答
  •  醉酒成梦
    2020-12-16 12:22

    Maven puts the files under /src/main/resouces/ into the default package of your classpath. Hence you can load through the classloader:

    InputStream in = getClass().getResourcesAsStream("temp.txt")
    

    For more information see Class#getResoucesAsStream.

提交回复
热议问题