Java-io-chararrayreader-marksupported
提供:Dev Guides
Java.io.CharArrayReader.markSupported()メソッド
説明
- java.io.CharArrayReader.markSupported()*メソッドは、ストリームがmark()をサポートしているかどうかをテストします。 char配列リーダーはmark()メソッドをサポートしています。
宣言
以下は* java.io.CharArrayReader.markSupported()*メソッドの宣言です-
public boolean markSupported()
パラメーター
NA
戻り値
ストリームがmark()呼び出しをサポートする場合、メソッドはtrueを返します。
例外
NA
例
次の例は、java.io.CharArrayReader.markSupported()メソッドの使用方法を示しています。
package com.finddevguides;
import java.io.CharArrayReader;
import java.io.IOException;
public class CharArrayReaderDemo {
public static void main(String[] args) { CharArrayReader car = null;
char[] ch = {'A', 'B', 'C', 'D', 'E'};
try {
//create new character array reader
car = new CharArrayReader(ch);
//verifies if the stream support mark() method
boolean bool = car.markSupported();
System.out.println("Is mark supported : "+bool);
System.out.println("Proof:");
//read and print the characters from the stream
System.out.println(car.read());
System.out.println(car.read());
//mark() is invoked at this position
car.mark(0);
System.out.println("Mark() is invoked");
System.out.println(car.read());
System.out.println(car.read());
//reset() is invoked at this position
car.reset();
System.out.println("Reset() is invoked");
System.out.println(car.read());
System.out.println(car.read());
System.out.println(car.read());
} catch(IOException e) {
//if I/O error occurs
e.printStackTrace();
} finally {
//releases any system resources associated with the stream
if(car!=null)
car.close();
}
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Is mark supported : true
Proof:
65
66
Mark() is invoked
67
68
Reset() is invoked
67
68
69