Different ways of loading a file as an InputStream

前端 未结 6 603
予麋鹿
予麋鹿 2020-11-22 04:02

What\'s the difference between:

InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName)

and

InputSt         


        
6条回答
  •  清酒与你
    2020-11-22 04:24

    After trying some ways to load the file with no success, I remembered I could use FileInputStream, which worked perfectly.

    InputStream is = new FileInputStream("file.txt");
    

    This is another way to read a file into an InputStream, it reads the file from the currently running folder.

提交回复
热议问题