Java.io.BufferedReader.markSupported() 方法



描述

java.io.BufferedReader.markSupported() 方法返回 true,如果流支援 mark() 方法。

宣告

以下是 java.io.BufferedReader.markSupported() 方法的宣告。

public boolean markSupported()

引數

返回值

該方法返回布林值。如果支援 mark(),則返回 true。

異常

示例

以下示例顯示了 java.io.BufferedReader.markSupported() 方法的使用。

package com.tutorialspoint;

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
java_io_bufferedreader.htm
廣告
© . All rights reserved.