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 文件在文件夹中时出现异常?
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01