Java.io.BufferedInputStream.markSupported() Method

Advertisements


Description

The java.io.BufferedInputStream.markSupported() method tests if the input stream type supports mark() and reset() methods. markSupported() method returns true for BufferedInputStream.

Declaration

Following is the declaration for java.io.BufferedInputStream.markSupported() method

public boolean markSupported()

Parameters

  • NA

Return Value

This method returns true if the stream type supports mark() and read() methods else the method returns false.

Exception

  • NA

Example

The following example shows the usage of java.io.BufferedInputStream.markSupported() method.

package com.tutorialspoint;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

public class BufferedInputStreamDemo {
   public static void main(String[] args) throws Exception {

      InputStream inStream = null;
      BufferedInputStream bis = null;
      boolean bool = false;
      
      try{

         // open input stream test.txt for reading purpose.
         inStream = new FileInputStream("c:/test.txt");

         // input stream is converted to buffered input stream
         bis = new BufferedInputStream(inStream);
         
         // returns true if mark() and read() supports
         bool = bis.markSupported();
         System.out.println("Support for mark() and reset() : "+bool);  
      
      }catch(Exception e){
         e.printStackTrace();
      }finally{

         // releases any system resources associated with the stream
         if(bis!=null)
            bis.close();
         if(inStream!=null)
            inStream.close();
      }
   }
}

Assuming we have a text file c:/test.txt, which has the following content. This file will be used as an input for our example program:

ABCDE 

Let us compile and run the above program, this will produce the following result:

Support for mark() and reset() : true




Advertisements
Advertisements