Rectangle 27 0

java Reading the content from an inputstream using scanner multiple times is not behaving as expected?


ByteArrayInputStream is = new ByteArrayInputStream("Hello World!!".getBytes());
    if(is.markSupported()){
        is.mark("Hello World!!".length());
    }
    System.out.println(getStreamContent(is));
    is.reset();
    System.out.println("Printed once");
    System.out.println(getStreamContent(is));

Things to note: I changed the variable type from InputStream to the instance type so I could call the methods specific to that type (mark, reset and markSupported ). That allows the stream to point back to the last marked position.

Note