【发布时间】:2021-02-26 13:09:30
【问题描述】:
我必须从 git 中的 \\resource 文件中读取外部文件。我必须使用资源文件夹,因为我与其他人共享项目,所以我们的 trainingData 文件的路径会有所不同。我写道:
public static String trainingFile = Trainer.class.getClassLoader().getResourceAsStream("trainingData.txt").toString();
然后trainingFile必须被阅读,我写道:
FileInputStream fstream = new FileInputStream(trainingFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
while ((strLine = br.readLine()) != null)
{
fileNames.add(strLine);
}
当我运行它时,它给了我错误:
Exception in thread "main" java.io.FileNotFoundException: java.io.BufferedInputStream@73035e27 (The system cannot find the file specified)
到“FileInputStream fstream”行。
非常感谢您的帮助。
【问题讨论】:
-
你看过
trainingFile的值了吗?如果没有,做。为什么你认为它有这个价值?
标签: java string file exception inputstream