To read data from my serial port I am using a inputStream and using BufferedReader for the inputStream. After each read I want clear the BufferedReader. Under the class BufferedReader there is no clear method. I tried to use reset() but it dint work. Any geeks here to suggest anything on this problem?
+1
A:
Just for readability - this is the code you posted in the comment (with the additional definition of str)
DataInputStream inStream = null;
String str = null;
BufferedReader bufRd = new BufferedReader(new InputStreamReader(inStream));
while((str = bufRd.readLine()) != null){
System.out.println(str);
}
Yes, it should work. There is no need to 'clear' or 'reset' a Stream or a Streamreader. Everything you read from the reader is 'taken from it', you will not see it again with the next read.
So if you really see items reappear on the Reader (and you haven't 'customized' the reader itself), then it is most likely, that your data source is sending the same data again and again. Check in that area.
Andreas_D
2009-12-02 08:27:38
Thanks a lot. I worked for me.
Surjya Narayana Padhi
2009-12-14 02:20:15
A:
What if i do that same bit, multiple times for different files, with different variable names, do i have to do something so that i don't get null's, and only the last read value?
Blah
2010-09-26 13:44:48