Netbeans FileReader FileNotFound Exception when the file is in folder?(Netbeans FileReader FileNotFound 文件在文件夹中时出现异常?)
问题描述
所以问题是每次我尝试在 NetBeans 或 Eclips 上加载下面的代码时都会抛出异常,但是当我尝试通过 TextMate 运行它时,一切正常!
so the problem is that I am having exception thrown each time I try to load the code below on NetBeans or Eclips, but when I try to run it thru TextMate everything works fine!
我尝试输入绝对地址,更改了文本文件等.没有帮助!
I tried to put the absolute address, changed the text file etc.. didn't help!
谁能帮助我或告诉我为什么它不能用 IDE 运行?
Can someone help me or tell why it won't run with IDE?
谢谢
void loadFile() {
try {
list = new LinkedList<Patient>();
FileReader read = new FileReader("a.txt");
Scanner scan = new Scanner(read);
while (scan.hasNextLine()) {
String Line = scan.nextLine();
String[] subArray = new String[5];
subArray = Line.split(",");
int a = Integer.parseInt(subArray[4]);
list.add(new Patient(Integer.parseInt(subArray[0]), subArray[1], subArray[2], subArray[3], a));
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "The file does not exist!" + "
Program is terminating.", "File Not Found", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
cap = list.size();
search_names = new int[cap];
for (int i = 0; i < list.size(); i++) {
search_names[i] = i;
}
setNames(search_names);
}//end loadFile
调试日志:没有/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar 的文件没有/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar 的文件没有/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar 的文件没有/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar 的文件}
推荐答案
在 netbeans 中,默认工作目录始终是根文件夹,我的意思是包含名称为src"、build"等文件夹的文件夹.文件连同这些文件夹,它就可以解决问题.
In netbeans the default working directory is always the root folder, i mean the folder which contains the folders which name "src", "build" etc. Place the file along with these folders and it will do the trick.
这篇关于Netbeans FileReader FileNotFound 文件在文件夹中时出现异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Netbeans FileReader FileNotFound 文件在文件夹中时出现异常?


- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01