【问题标题】:How to search file and grab the field needed?如何搜索文件并获取所需字段?
【发布时间】:2014-12-10 23:07:31
【问题描述】:

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

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

【问题讨论】:

  • hs_err_pid5036.log 文件中有什么信息吗?如果您尝试从命令行编译并运行它会发生什么?

标签: java eclipse readfile


【解决方案1】:

您的 close 语句在您的 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();

【讨论】:

  • 好的。我不确定,因为我的观察可能是许多错误之一。 C:\Users\ximinmi\workspace\OldImageReveal\hs_err_pid5036.log 的文件是怎么说的?
  • 使用try-with-resources 会更好,但这不应该导致 OP 看到的致命错误。我怀疑这是一条红鲱鱼。
  • --------------- T H R E A D --------------- 当前线程(0x0130d400):JavaThread“未知线程” [_thread_in_vm, id=4704, stack(0x00ce0000,0x00d30000)] 堆栈:[0x00ce0000,0x00d30000],sp=0x00d2f970,可用空间=318k 本机帧:(J=编译的Java代码,j=解释,Vv=VM代码,C =本机代码) V [jvm.dll+0x190494] V [jvm.dll+0x18a116] V [jvm.dll+0x35d7a] V [jvm.dll+0x35e06] V [jvm.dll+0x4465d] V [jvm.dll+ 0x4490e] V [jvm.dll+0x92f8a] V [jvm.dll+0x9333b] V [jvm.dll+0x13fa31]
  • @frenchDolphin:我在帖子中的错误信息,然后是上面的错误信息。
  • This post 似乎表明您的运行配置有问题。转到运行 -> 运行配置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多