BufferedReader/ readline() problem

Hope some can help me out with this:

I've got a class which accesses a file using the following:

in = new BufferedReader(new FileReader(filePath));

then parses through the file line by line, using readline(). Pretty standard.

I instantiate TWO of these objects from a servlet, and each separate object accesses its own unique file.

That said, the two objects should have nothing to do with eachother.

Everything's fine with my first object. The problem arises with the second one. It's constructed fine, and the BufferedReader is created without incident, but I ALWAYS get an IOException when I try to readline() from it.

Like I said, I'm doing the very same thing with the first object, without problems. I've tested each separately, and each works fine without the other.

I think it must be some sort of memory thing that I'm missing. Can anyone help?

[948 byte] By [snack00] at [2007-9-26 2:10:31]
# 1
Could you post the code?
schapel at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...
# 2

Three methods...getMailText is the controller.

//class level

boolean marked = false;

String out = new String();

File file;

public class MailTemplateParser(File _file){

file=_file;

}

public String getMailText() throws IOException, Exception {

BufferedReader reader = this.readInFile(file);

String textLine = this.getLineOfText(reader);

String modifiedTextLine = this.getModifiedLineOfText(textLine);

while(!textLine.endsWith("<end file>")) {

textLine = this.getLineOfText(reader);

modifiedTextLine = this.getModifiedLineOfText(textLine);

}

reader.close();

return out;

}

public BufferedReader readInFile(File _file) throws FileNotFoundException, IOException {

String fileText = "";

String filePath = _file.getPath();

dc.logMessage("filepath" + filePath);

in = new BufferedReader(new FileReader(filePath));

return in;

}

public String getLineOfText(BufferedReader _in) throws IOException {

String line = new String();

try {

if (marked) {

_in.reset();

}

line = _in.readLine();

_in.mark(0);

marked = true;

}

catch(IOException ex) {

ex.printStackTrace();

_in.close();

}

return line;

}

snack00 at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...
# 3
only 3 relevant methods, that is...
snack00 at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...
# 4

I can't see any reason why your program would display such behavior...if it was a memory problem, it will prompt a message stating to have run out of heap mem...

hm...

Aside from it been sloppy =), I can't see something wrong with it. How exacly are you creating these objects?

Shrubz

shrubz at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...
# 5

What are you trying to do with mark and reset? According to the documentation for mark, the int value passed to it gives the limit of the number of charcaters you can read before you reset again. But since you set the limit to 0, it makes sense that marking, reading some text, then resetting would throw an IOException. I have no idea why you get an IOException with two Files open and not when you have only one open.

schapel at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...
# 6

Thank you, schrubz and schapel, for your attention.

Regarding the mark() question. I'm not certain why, but it initially works the way I want it to with the read ahead limit= 0. Doesn't really make much sense though. I'll mess with the value and repost on 7/30

As for creating the objects, I don't do anything special...

schrubz, on a side note, can you help me clean the code up? I'd really appreciate your help, even if it's just a couple of specific words of constructive criticism.

snack00 at 2007-6-29 9:01:29 > top of Java-index,Archived Forums,Java Programming...