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.
Answer from Andreas Dolk on Stack OverflowJust 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.
Try to make a new instance of buffer
BufferedReader br = new BufferedReader(newInputStreamReader(socket.getInputStream())); //create
String read = br.readLine(); //read line
br = new BufferedReader(newInputStreamReader(socket.getInputStream()));
I'm using socket communication so here is socket example. I hope I helped you
The BufferedWriter will already flush when it fills its buffer. From the docs of BufferedWriter.write:
Ordinarily this method stores characters from the given array into this stream's buffer, flushing the buffer to the underlying stream as needed.
(Emphasis mine.)
The point of BufferedWriter is basically to consolidate lots of little writes into far fewer big writes, as that's usually more efficient (but more of a pain to code for). You shouldn't need to do anything special to get it to work properly though, other than making sure you flush it when you're finished with it - and calling close() will do this and flush/close the underlying writer anyway.
In other words, relax - just write, write, write and close :) The only time you normally need to call flush manually is if you really, really need the data to be on disk now. (For instance, if you have a perpetual logger, you might want to flush it every so often so that whoever's reading the logs doesn't need to wait until the buffer's full before they can see new log entries!)
The ideal flushing moment is when you need another program reading the file to see the data that's been written, before the file is closed. In many cases, that's never.