![](/img/trans.png)
[英]Where to put text files in an Eclipse Dynamic Web Project using Tomcat?
[英]Eclipse dynamic web project : where should I put resource files
我正在嘗試制作蝕動態Web項目。 我嘗試將pdf文件放入項目的“ WEB-INF”目錄中。 但是當我嘗試使用獲取輸入流時
InputStream inStream = getServletContext().getResourceAsStream("/WEB-INF/mypdf.pdf");
我得到inStream = null
。 我還嘗試將mypdf.pdf
文件放在我試圖從中獲取輸入流並使用的類的目錄中
InputStream inStream = getServletContext().getResourceAsStream("mypdf.pdf");
再次返回inStream = null
有什么建議嗎?
你可以用
this.getClass().getResourceAsStream("mypdf.pdf");
如果文件位於類所在的目錄中。
getResourceAsStream在類路徑上搜索文件
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("your pdf file");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.