getResourceAsStream()返回值为null
javaWeb项目,写文件下载的时候遇到getServletContext().getResourceAsStream("/store/"+filename)获取的值为null
//获得读取本地文件的输入流
in = getServletContext().getResourceAsStream("/store/"+filename);
目录结构如下
查询后发现,他们的下载目录都放入web目录下(可能与Resource Folders有关,和上一个bug类似)
但将文件放入web目录下并没有设置Resource Folder之后,下载操作就没有bug
目录结构如下图所示
代码为:
in = getServletContext().getResourceAsStream("/WEB-INF/store/"+filename);
参考https://stackoverflow.com/questions/14997523/getresourceasstream-returns-null-inspite-of-using-servletcontext
https://blog.csdn.net/AsCoolCucmber/article/details/115466886?spm=1005.2026.3001.5635&utm_medium
标签:getResourceAsStream,getServletContext,filename,返回值,null,目录,store From: https://www.cnblogs.com/debug-compass/p/17483947.html