English 中文(简体)
Netbeans fileReader file Not Found 档案夹的例外情况?
原标题:Netbeans FileReader FileNotFound Exception when the file is in folder?

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!

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

Debug log: Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar Have no file for /System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar Have no file for /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar }

最佳回答

在净户中,违约的工作名录总是根切,即包含“弧”、“泡沫”等的夹。 将档案与这些文件夹放在一起,并将做trick。

问题回答

下面是Net Beans IDE 7.0.1号步骤程序的步骤。

  1. Click on File menu.
  2. Click on Project Properties.
  3. In the categories, select Run.
  4. In main class you select your current java file.
  5. In Arguments select the file you want to read for e.g. abc.txt or abc.java
  6. And in Working Directory write down the path of folder in which this abc.txt or abc.java lies.
  7. Click OK to close Project Properties.
  8. While running your program don t forget to select your project as Main Project.
  9. Then click F^ on keyboard. i.e. You have to raun your main project instead of just running your current java file. That s it....enjoy!!!!

最后找到了解决办法。

In eclipse you should put the target file in project folder. Guess same applies to NetBeans.

我在“弧”夹中拥有目标档案(在实际编码档案中)。 事实上,在项目夹处的地方,我不得不将该项目改变为上倍。

简单易懂。

或许,在你的不同设置中,你有不同的“工作名录”。 您可以检查一下您的目录,如:

System.out.println(new File(".").getAbsoluteFile());

在ec忙中,你可以在管理组合中设立工作名录,提出论点。

Try BufferedReader?

EDIT: Edited to show example more closely to your code. I got excepption when using File Reader. But was able to .println with BufferedReader. I did not use Scanner.

EDIT2: I was also able to get your code to work. With Scanner etc(When using full path) (Example: FileReader read = new FileReader(""C:\myfolder\folder\a.txt". So hmmm.

  try {
  list = new LinkedList<Patient>();
  BufferedReader scan = new BufferedReader(new FileReader("C:\a.txt"));
  String lines;
            try {
                // Scanner scan = new Scanner(read);
                while ((lines = scan.readLine()) != null) {
                 //I just printed lines you will do your stuff here
                    System.out.println(lines);
                    }
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, "The file does not exist!" + "
Program is terminating.", "File Not Found", JOptionPane.INFORMATION_MESSAGE);
      System.exit(0);     
        }

右上点击你的文本档案中选择了这些特性,并抄录了这条道路,并将其贴在你进入你档案的地方。

lets say you wanna add test.txt in netbeans

if your project in C:myProject put the text file inside C:myProject file directly not in the C:myProjectsrc . then use:

File file = new File("test.txt");

扫描仪=新的扫描仪(档案);

页: 1

斯堪纳输入=新斯纳(新档案(“测试”));





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签