Home » Java programming language

Java InputStream markSupported() Method with Example

InputStream Class markSupported() method: Here, we are going to learn about the markSupported() method of InputStream Class with its syntax and example.
Submitted by Preeti Jain, on April 03, 2020

InputStream Class markSupported() method

  • markSupported() method is available in java.io package.
  • markSupported() method is used to check whether this stream supports mark(), reset() or not.
  • markSupported() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • markSupported() method does not throw an exception at the time of checking the supporting methods.

Syntax:

    public boolean markSupported();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is boolean, it returns true when this stream supports mark(), reset() method otherwise it returns false.

Example:

// Java program to demonstrate the example 
// of boolean markSupported() method
// of InputStream

import java.io.*;

public class MarkSupportedOfIS {
 public static void main(String[] args) throws Exception {
  InputStream is_stm = null;
  int val = 0;

  try {
   // Instantiates FileInputStream
   is_stm = new FileInputStream("D:\\includehelp.txt");

   // By using markSupported() method is to
   // check whether this stream is_stm supports
   // mark() method or not

   boolean status = is_stm.markSupported();
   System.out.println("is_stm.markSupported(): " + status);
  } catch (Exception ex) {
   System.out.println(ex.toString());

  } finally {
   // with the help of this block is to
   // free all necessary resources linked
   // with the stream
   if (is_stm != null) {
    is_stm.close();
   }
  }
 }
}

Output

is_stm.markSupported(): false



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.