0

I tried the following code to understand the working of mark() method of ByteArrayInputStream.

class tryByteArray  
{  
    public static void main(String args[]) throws Exception  
    {  
        byte[] buffer={71, 69, 69, 75, 83};  
        try(ByteArrayInputStream obj=new ByteArrayInputStream(buffer))  
        {  
            System.out.println("\nChar "+(char)obj.read());  
            obj.mark(0);  
            System.out.println("Char "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
            obj.reset();  
            System.out.println("\nChar "+(char)obj.read());  
            System.out.println("Char "+(char)obj.read());  
          }  
    }  
}

It gave the following output:-

Char G
Char E
Char E
Char K

Char E
Char E  

But when I changed the argument of mark() method to 1,2 or any number it still shows the same output. Can someone explain to me the working of mark() method?

Reegan Miranda
  • 2,879
  • 6
  • 43
  • 55
Kushagra
  • 89
  • 11

1 Answers1

1

From the docs:

Note: The readAheadLimit for this class has no meaning.

Edit: Also take a look at the source code.