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 Overflow
🌐
Tutorialspoint
tutorialspoint.com › java › io › bufferedwriter_flush.htm
Java - BufferedWriter flush() method
The Java BufferedWriter flush() flushes the characters from a write buffer to the character or byte stream as an intended destination. flush() method is used to write text to a character-based output stream, buffering the characters for efficient
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › BufferedReader.html
BufferedReader (Java Platform SE 7 )
BufferedReader in = new BufferedReader(new FileReader("foo.in")); will buffer the input from the specified file.
🌐
Tabnine
tabnine.com › home page › code › java › java.io.bufferedwriter
java.io.BufferedWriter.flush java code examples | Tabnine
BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter("test.txt")); bw.write("test"); bw.flush(); // you can omit this if you don't care about errors while flushing bw.close(); // you can omit this if you don't care about errors while closing } catch (IOException e) { // error handling (e.g.
🌐
GeeksforGeeks
geeksforgeeks.org › java › bufferedwriter-flush-method-in-java-with-examples
BufferedWriter flush() method in Java with Examples - GeeksforGeeks
May 28, 2020 - The flush() method of BufferedWriter class in Java is used to flush the characters from the buffered writer stream.
🌐
Tabnine
tabnine.com › home page › code › java › java.io.bufferedreader
Java Code Examples for BufferedReader | Tabnine
String urlParameters = "param1=a&param2=b&param3=c"; URL url = new URL("http://example.com/index.php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(urlParameters); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { System.out.println(line); } writer.close(); reader.close();
🌐
Coderanch
coderanch.com › t › 275906 › java › clear-reset-buffer-BufferedReader
how to clear/reset buffer when I use BufferedReader? (I/O and Streams forum at Coderanch)
November 19, 2002 - hi! in my program, I use BufferedReader to get a string at a time from another program using socket. anyway, I have BufferedReader in and I call in.readLine() inside the while loop. It's not starting to read from the beginning each time. ie. inside while loop 1)a string "abc" shows up, in.readLine() reads "abc" 2)the second string "def" shows up, in.readLine() is reading "abcdef"!
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › BufferedWriter.html
BufferedWriter (Java Platform SE 8 )
March 16, 2026 - Ordinarily this method stores characters from the given array into this stream's buffer, flushing the buffer to the underlying stream as needed. If the requested length is at least as large as the buffer, however, then this method will flush the buffer and write the characters directly to the ...
Find elsewhere
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › io.BufferedReader.flush.html
io.BufferedReader.flush — Python Standard Library
Docs » · api » · io » · io.BufferedReader » · io.BufferedReader.flush · View page source · io.BufferedReader.flush¶ · BufferedReader · flush · Next Previous
🌐
Coderanch
coderanch.com › t › 487134 › certification › Function-close-flush-methods
Function of close() and flush() methods.. (OCPJP forum at Coderanch)
Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect. The flush() method ensures stream flushing. Practice shows that usually stuff gets written to file with just close() method.
🌐
CodeGym
codegym.cc › java blog › java io & nio › bufferedreader and bufferedwriter
Java bufferedreader and java bufferedwriter
October 11, 2023 - close() // Close the stream flush() // Send the data from the buffer to the Writer newLine() // Move to a new line write(char[] cbuf, int off, int len) // Write to the buffer write(int c) // Write to the buffer write(String s, int off, int len) // Write to the buffer
🌐
Medium
medium.com › @NanaAma3110 › importance-of-using-bufferedreader-and-bufferedwriter-in-java-programming-e9ea177bcccb
Importance Of Using BufferedReader and BufferedWriter in Java Programming. | by Nana Ama Agyeman | Medium
September 22, 2015 - Also if the idea of closing the stream does not appeal to you, you can opt to flush the buffer into the file, by using the flush() method. All the methods can throw an IOException, so be sure to wrap the BufferedWriterin a try-catch block.
🌐
CodeGym
codegym.cc › courses › java collections › bufferedreader, bufferedwriter
Course Java Collections - Lecture: BufferedReader, BufferedWriter
"After you're done writing, you need to call the flush() method on the BufferedWriter object to force it to send any data still in the buffer to the Writer."
🌐
Python
docs.python.org › 3 › library › io.html
io — Core tools for working with streams
January 30, 2026 - The BufferedIOBase ABC extends IOBase. It deals with buffering on a raw binary stream (RawIOBase). Its subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer raw binary streams that are writable, readable, and both readable and writable, respectively.
🌐
GeeksforGeeks
geeksforgeeks.org › java › bufferedwriter-close-method-in-java-with-examples
BufferedWriter close() method in Java with Examples - GeeksforGeeks
May 28, 2020 - The close() method of BufferedWriter class in Java is used to flush the characters from the buffer stream and then close it. Once the stream is closed further calling the methods like write() and append() will throw the exception.
🌐
IncludeHelp
includehelp.com › java › bufferedwriter-flush-method-with-example.aspx
Java BufferedWriter flush() Method with Example
// Java program to demonstrate the example // of Writer flush() method of // BufferedWriter import java.io.*; public class FlushBW { public static void main(String[] args) { String str = "Java Programming"; try { // Instantiates StringWriter StringWriter str_w = new StringWriter(); // Instantiates BufferedWriter BufferedWriter buff_w = new BufferedWriter(str_w); for (char ch: str.toCharArray()) { // To append character by using // append() to the writer buff_w.append(ch); // It flushes the characters // from buff_w to char or byte // stream buff_w.flush(); // Display Buffer from str_w System.out.println("str_w.getBuffer():" + str_w.getBuffer()); } // Close the stream buff_w.close(); } catch (IOException ex) { System.out.println("buff_w: " + ex.getMessage()); } } }
🌐
Medium
medium.com › @isaacjumba › why-use-bufferedreader-and-bufferedwriter-classses-in-java-39074ee1a966
Why use BufferedReader and BufferedWriter Classses in Java | by Isaac Jumba | Medium
September 23, 2015 - Flushing is the operation that tells the BufferedWriter to write everything onto the output file. Using a buffer is what makes both BufferedReader and BufferedWriter fast and efficient.