getResourceAsStream() vs FileInputStream

前端 未结 6 850
旧巷少年郎
旧巷少年郎 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 07:04

    getResourceAsStream is the right way to do it for web apps (as you already learned).

    The reason is that reading from the file system cannot work if you package your web app in a WAR. This is the proper way to package a web app. It's portable that way, because you aren't dependent on an absolute file path or the location where your app server is installed.

提交回复
热议问题