系统找不到指定的路径-文本文件 [英] The system cannot find the path specified - text file
本文介绍了系统找不到指定的路径-文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在此项目中添加了一个文本文件,如下所示:
I added a text file to my project as in this path:
Myproject/WebPages/stopwords.txt
Myproject/WebPages/stopwords.txt
图片: http://s7.postimg.org/w65vc3lx7/Untitled.png
我试图打开文件,但不能!
I tried to open the file, but i can't !
我的代码:
BufferedReader br = new BufferedReader(new FileReader("stopwords.txt"));
StringBuilder sb = new StringBuilder();
String line = br.readLine();
错误:stopwords.txt(系统找不到指定的路径)
Error: stopwords.txt (The system cannot find the path specified)
推荐答案
您可以尝试类似的
我猜你在 .jsp 文件中.
<%
String path = request.getServletContext().getRealPath("/WebContent/stopwords.txt") ;
BufferedReader br = new BufferedReader(new FileReader(path));
// other codes...
%>
已
<%
String path = request.getServletContext().getRealPath("/stopwords.txt") ;
//check here with print path variable...
// you can pass this path variable to invoke method which is reside into //your java class...
BufferedReader br = new BufferedReader(new FileReader(path));
%>
这篇关于系统找不到指定的路径-文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文