Class.getResourceAsStream(String path) :

  1 在类的同级目录下path直接写资源名

  2 在当前类的目录的子目录下path写当前类的相对路径

Class.getClassLoader.getResourceAsStream(String path):

  既不在当前类的同级目录下,也不在当前类的子目录下,使用这种方法,path默认是以ClassPath根目录起始

  Eclipse中文件在src/main/resources中时直接写文件名即可

ServletContext. getResourceAsStream(String path):

  获取web项目下的资源,path默认是以WEBAPP的根目录起始

相关文章:

  • 2021-10-27
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2021-10-05
  • 2021-09-28
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案