如何搜索文件并获取所需的字段?

时间:2014-12-10 23:07:32

标签: java eclipse readfile

java新手。现在我正在尝试打开,读取和搜索文件,但Eclipse给了我一个错误。这是我的代码:

import java.io.*;

class Test2 {
  public static void main(String[] args) {
    try {            
      BufferedReader doc = new BufferedReader(new FileReader("E:\\Grad\\Project\\test.csv"));
      /* String userInput;    */
      String docCont = new String();
      while ((docCont = doc.readLine()) != null) {
        System.out.println(docCont);
        doc.close();
      }
    } catch(IOException ie) {
      ie.printStackTrace();
    }
  }
}   

代码编译,但是当我尝试运行它时,我得到了这个:

A fatal error has been detected by the Java Runtime Environment:

Internal Error (javaClasses.cpp:136), pid=5036, tid=4704
fatal error: Invalid layout of preloaded class

JRE version:  (7.0_67-b01) (build )
Java VM: Java HotSpot(TM) Client VM (24.65-b04 mixed mode windows-x86 )
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as:
C:\Users\ximinmi\workspace\OldImageReveal\hs_err_pid5036.log

If you would like to submit a bug report, please visit:
  http://bugreport.sun.com/bugreport/crash.jsp

知道这是关于什么的吗?感谢。

1 个答案:

答案 0 :(得分:0)

你的密切语句在你的while循环中,所以在第一次迭代时,你将无法再从你的阅读器中读取。写下这个:

BufferedReader doc = new BufferedReader(new FileReader("E:\\Grad\\Project\\test.csv"));
String docCont = new String();
while ((docCont = doc.readLine()) != null) {
    System.out.println(docCont);
}
doc.close();