Java.io.InputStream.markSupported() Method



Description

The java.io.InputStream.markSupported() method tests if this input stream supports the mark() and reset() method.

Declaration

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

public boolean markSupported()

Parameters

NA

Return Value

The method returns true if this stream supports instance the mark and reset method.

Exception

NA

Example

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

package com.tutorialspoint;

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

public class InputStreamDemo {
   public static void main(String[] args) throws Exception {
      InputStream is = null;
      boolean bool = false;      
      
      try {
         // new input stream created
         is = new FileInputStream("C://test.txt");
         
         // returns true if the mark()/reset() supported.
         bool = is.markSupported();
         
         // prints
         System.out.print("Is mark()/reset() supported? ");
         System.out.print(bool);
         
      } catch(Exception e) {
         // if any I/O error occurs
         e.printStackTrace();
      } finally {
         // releases system resources associated with this stream
         if(is!=null)
            is.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 −

ABCDEF

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

Is mark()/reset() supported? false
java_io_inputstream.htm
Advertisements