need help parsing and large file reading-urgent please

import java.io.*;

import java.lang.String.*;

import java.util.*;

public class ReadFile {

//--< main >--//

public static void main (String[] args) {

ReadFile t = new ReadFile();

t.readMyFile();

}

//--< readMyFile >--//

void readMyFile() {

String line = null;

String dcn = null;

String pfn = null;

String pln = null;

String pdob = null;

String ssd = null;

try {

FileReader fr= new FileReader("C:\\ClaimsData\\ClaimsExtract.txt");

BufferedReader br = new BufferedReader(fr);

line = new String();

while ((line = br.readLine()) != null) {

//A00002314376A5272201102300000000MASARUOKUDA 1933012520050722B10120051001

//Each line of ClaimsExtract.txt is exactly in above form

// and there are about 1000 such lines

dcn = new String();

pfn = new String();

pln = new String();

pdob = new String();

ssd = new String();

dcn = line.substring(13,24);

pfn = line.substring(32,42);

pln = line.substring(42,57);

pdob = line.substring(57,65);

ssd = line.substring(65,73);

//System.out.println(dcn+" "+pfn+" "+pln+" "+pdob+" "+ssd);

fr.close();

}

} catch (IOException e) {

// catch possible io errors from readLine()

System.out.println("Uh oh, got an IOException error!");

e.printStackTrace();

}

} // end of readMyFile()

} // end of class

java.io.IOException: Stream closed

at sun.nio.cs.StreamDecoder.ensureOpen(StreamDecoder.java:37)

at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:152)

at java.io.InputStreamReader.read(InputStreamReader.java:167)

at java.io.BufferedReader.fill(BufferedReader.java:136)

at java.io.BufferedReader.readLine(BufferedReader.java:299)

at java.io.BufferedReader.readLine(BufferedReader.java:362)

at ReadFile.readMyFile(ReadFile.java:32)

at ReadFile.main(ReadFile.java:14)

Uh oh, got an IOException error!

I also tried using Tokenizer but some other errors, Please suggest a better approach

urgent , Thanks in Advance

[2194 byte] By [babusai1a] at [2007-10-2 20:10:38]
# 1
Hi,Remove the call fr.close() from the loop. The reader should be closed after the loop.Kaj
kajbja at 2007-7-13 22:51:14 > top of Java-index,Java Essentials,Java Programming...
# 2

These lines:

dcn = new String();

pfn = new String();

pln = new String();

pdob = new String();

ssd = new String();

Are also totally useless. They just allocate extra objects which aren't used.

Kaj

kajbja at 2007-7-13 22:51:14 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi KajThanks a lot for the reply, I will try now and get backThnk Youbaba
babusai1a at 2007-7-13 22:51:14 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi Kaj

I tried moving fr.close outside the loop. Now I am getting different error

Can you please suggest how I can eliminate this ?

java.lang.StringIndexOutOfBoundsException: String index out of range: 24

at java.lang.String.substring(String.java:1441)

at ReadFile.readMyFile(ReadFile.java:38)

at ReadFile.main(ReadFile.java:14)

Exception in thread "main"

babusai1a at 2007-7-13 22:51:14 > top of Java-index,Java Essentials,Java Programming...
# 5

i think your while loop has the problem. It's keep continuing to read the next line in the file and doesn't exit even when it reaches the end of file. Therefore it gives you that error. Since you're using variable line as string object hence for the while loop you should've something like this and i would also move the reading next line part just before ending the while loopwhile ( ! line.equals(null) ) {

line = br.readLine();

}//end of while

[b]because string object doesn't work for comparing operators == or != so you always have to use string.equlas()[/b]

I'm sure that's the reason you're encountering this error, otherwise please specify the line where you're encountring the problem. Next time please use the [code] tags for your code becuase it formats the code nicely and it's easy to read it. Cheers

Message was edited by:

salubadsha

salubadshaa at 2007-7-13 22:51:14 > top of Java-index,Java Essentials,Java Programming...