This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble with buffered Reader  RSS feed

 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to read data from a file using a BufferdReader object and then compare it to a String that is determent by args[1] , if it matches i add the data to vector A and if not to vector B , then i write all data in the two vectors to files , this all works nicely and then new file that was not suppose to have the data specivied by args[1] doesn't have any data of it...
so this all works fine, but when is delete the file all data was read from and rename the new file to this file it says it again found that data that i removed, so i am thinking that because it is a BufferedReader the buffers are not cleared , but how can i clear the buffers of a BufferedReader, there is no method called flush() like for a bufferedWriter, does java clear the buffers itself ???
please help here is the read code
public void ReadFile(BufferedReader in, String testText) {
Vector dataBlock = new Vector();
boolean record = false;
String data;
String openBlock = new String("ITEM");
String closeBlock = new String("}");
try {
while ((data = in.readLine()) != null) {
if (openBlock.equalsIgnoreCase(data)) {
record = true;
}
while (record == true) {
data = in.readLine();
dataBlock.addElement(data);
if (closeBlock.equalsIgnoreCase(data)) {
record = false;
this.formatArray(dataBlock, testText);
}
}
}
} catch (IOException e ) {}
}
 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all, dont worry, i found the prob
I way closeing and destroying the reffrence to the bufferedReader in the wrong scope
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!