Java-io-filterinputstream-marksupported

提供:Dev Guides
移動先:案内検索

Java.io.FilterInputStream.markSupported()メソッド

説明

  • java.io.FilterInputStream.markSupported()*メソッドは、この入力ストリームがmark()およびreset()呼び出しをサポートするかどうかをテストします。

宣言

以下は* java.io.FilterInputStream.markSupported()*メソッドの宣言です-

public boolean markSupported()

パラメーター

NA

戻り値

ストリームタイプがマークおよびリセットメソッドをサポートしている場合、メソッドはtrueを返します。

例外

NA

次の例は、java.io.FilterInputStream.markSupported()メソッドの使用方法を示しています。

package com.finddevguides;

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

public class FilterInputStreamDemo {
   public static void main(String[] args) throws Exception {
      InputStream is = null;
      FilterInputStream fis = null;
      boolean bool = false;

      try {
        //create input streams
         is = new FileInputStream("C://test.txt");
         fis = new BufferedInputStream(is);

        //tests if the input stream supports mark() and reset()
         bool = fis.markSupported();

        //prints
         System.out.print("Supports mark and reset methods: "+bool);

      } catch(IOException e) {
        //if any I/O error occurs
         e.printStackTrace();
      } finally {
        //releases any system resources associated with the stream
         if(is!=null)
            is.close();
         if(fis!=null)
            fis.close();
      }
   }
}

テキストファイル* c:/test.txt*があり、次の内容があるとします。 このファイルは、サンプルプログラムの入力として使用されます-

ABCDEF

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Supports mark and reset methods: true