getResourceAsStream() vs FileInputStream

前端 未结 6 869
旧巷少年郎
旧巷少年郎 2020-11-21 06:09

I was trying to load a file in a webapp, and I was getting a FileNotFound exception when I used FileInputStream. However, using the same path, I wa

6条回答
  •  自闭症患者
    2020-11-21 06:54

    The FileInputStream class works directly with the underlying file system. If the file in question is not physically present there, it will fail to open it. The getResourceAsStream() method works differently. It tries to locate and load the resource using the ClassLoader of the class it is called on. This enables it to find, for example, resources embedded into jar files.

提交回复
热议问题