Use Absolute path for ClassLoader getResourceAsStream()

删除回忆录丶 提交于 2019-12-05 03:25:53

If you have a native file path then you don't need to use getResourceAsStream, just create a FileInputStream in the normal way.

Properties props = new Properties();
FileInputStream in = new FileInputStream("C:\\someprops.properties");
try {
  props.load(in);
} finally {
  in.close();
}

(you may want to wrap the FileInputStream in a BufferedInputStream if the file is large)

The method classloader.getResourceAsStream looks up resources on the classpath. If you want to load your someprops.properties file with classloader.getResourceAsStream then add it to your classpath. Otherwise, if this is a properties file, you could always use the Properties.load method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!