IntelliJ Java IDE
The moose likes I/O and Streams and the fly likes Trouble with buffered Reader Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Trouble with buffered Reader " Watch "Trouble with buffered Reader " New topic
Author

Trouble with buffered Reader

hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
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 ) {}
}


Any Body can be paid to write good code, but brilliant code can only come from passion
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Hey all, dont worry, i found the prob
I way closeing and destroying the reffrence to the bufferedReader in the wrong scope
 
 
subject: Trouble with buffered Reader
 
Threads others viewed
Really Challenging...HelpMe..java.Util - very Urgent
Not able to send a mail using JAVA code
Java I/O
File I/O R/W + Permission Issue
using BufferedReader and looping
IntelliJ Java IDE