gpt4 book ai didi

java - 系统找不到指定的路径-文本文件

转载 作者:行者123 更新时间:2023-12-01 10:49:55 31 4
gpt4 key购买 nike

我将一个文本文件添加到我的项目中,如下路径所示:

Myproject/WebPages/stopwords.txt

图片: http://s7.postimg.org/w65vc3lx7/Untitled.png

我尝试打开该文件,但打不开!

我的代码:

BufferedReader br = new BufferedReader(new FileReader("stopwords.txt"));
StringBuilder sb = new StringBuilder();
String line = br.readLine();

错误: stopwords.txt(系统找不到指定的路径)

最佳答案

你可以尝试类似的方法,

我猜你在 .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));


%>

关于java - 系统找不到指定的路径-文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33977106/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com