0

New to java. Now I am trying to open, read and search a file, but Eclipse is giving me an error. Here is my code:

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();
    }
  }
}   

The code compiles, but when I try to run it I get this:

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

Any idea what this is about? Thanks.

dimo414
  • 47,227
  • 18
  • 148
  • 244
Q-ximi
  • 941
  • 3
  • 14
  • 21
  • Is there anything informative in that `hs_err_pid5036.log` file? What happens if you try to compile and run this from the command line? – dimo414 Dec 10 '14 at 23:23

1 Answers1

0

Your close statement is in your while loop, so on the first iteration, you will no longer be able to read from your reader. Write this instead:

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();
jfdoming
  • 975
  • 10
  • 25
  • OK. I'm not sure, as my observation could be one of many errors. What does the file at `C:\Users\ximinmi\workspace\OldImageReveal\hs_err_pid5036.log` say? – jfdoming Dec 10 '14 at 23:20
  • Even better would be to use [`try-with-resources`](http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html), but that shouldn't cause the fatal error OP is seeing. I suspect this is a red herring. – dimo414 Dec 10 '14 at 23:24
  • --------------- T H R E A D --------------- Current thread (0x0130d400): JavaThread "Unknown thread" [_thread_in_vm, id=4704, stack(0x00ce0000,0x00d30000)] Stack: [0x00ce0000,0x00d30000], sp=0x00d2f970, free space=318k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) 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] – Q-ximi Dec 10 '14 at 23:24
  • @frenchDolphin: The error message I put in the post followed by the one above. – Q-ximi Dec 10 '14 at 23:25
  • [This post](http://stackoverflow.com/a/15840413/3761440) seems to suggest that it is a problem with your run configuration. Go to Run -> Run Configurations – jfdoming Dec 10 '14 at 23:33