用户登录
用户注册

分享至

Netbeans FileReader FileNotFound 文件在文件夹中时出现异常?

  • 作者: 南枫晔
  • 来源: 51数据库
  • 2023-01-29

问题描述

所以问题是每次我尝试在 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.

软件
前端设计
程序设计
Java相关