Java-io-bufferedreader-marksupported

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

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

説明

ストリームが* mark()メソッドをサポートしている場合、 java.io.BufferedReader.markSupported()*メソッドはtrueを返します。

宣言

以下は* java.io.Bufferedreader.marksupported()*メソッドの宣言です。

public boolean markSupported()

パラメーター

NA

戻り値

メソッドはブール値を返します。 mark()がサポートされている場合、trueを返します。

例外

NA

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

package com.finddevguides;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class BufferedReaderDemo {
   public static void main(String[] args) throws Exception {
      InputStream is = null;
      InputStreamReader isr = null;
      BufferedReader br = null;

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

        //create new input stream reader
         isr = new InputStreamReader(is);

        //create new buffered reader
         br = new BufferedReader(isr);

         boolean bool = false;

        //returns true if the stream type supports mark
         bool = br.markSupported();

         System.out.println("Buffered reader supports mark : "+bool);

      } catch(Exception e) {
         e.printStackTrace();
      } finally {
        //releases resources associated with the streams
         if(is!=null)
            is.close();
         if(isr!=null)
            isr.close();
         if(br!=null)
            br.close();
      }
   }
}

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

ABCDE

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

Buffered reader supports mark : true