Reloading resources loaded by getResourceAsStream

后端 未结 3 1682
無奈伤痛
無奈伤痛 2021-02-13 23:44

Following best practices, I\'m using Thread.currentThread().getContextClassLoader().getResourceAsStream to load resources in a web application (like text files or x

3条回答
  •  不思量自难忘°
    2021-02-14 00:06

    Try this:

    ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
    URL resURL = ctxLoader.getResource(resName);
    URLConnection resConn = resURL.openConnection();
    resConn.setUseCaches(false);
    InputStream resIn = resConn.getInputStream();
    ...
    

提交回复
热议问题