Java.io.BufferedInputStream.markSupported() 方法



描述

java.io.BufferedInputStream.markSupported() 方法測試輸入流型別是否支援mark()reset() 方法。markSupported() 方法對BufferedInputStream 返回 true。

宣告

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

public boolean markSupported()

引數

返回值

如果流型別支援mark()read() 方法,則此方法返回true;否則返回false

異常

示例

以下示例演示了 java.io.BufferedInputStream.markSupported() 方法的用法。

package com.tutorialspoint;

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

public class BufferedInputStreamDemo {
   public static void main(String[] args) throws Exception {
      InputStream inStream = null;
      BufferedInputStream bis = null;
      boolean bool = false;
      
      try {
         // open input stream test.txt for reading purpose.
         inStream = new FileInputStream("c:/test.txt");

         // input stream is converted to buffered input stream
         bis = new BufferedInputStream(inStream);
         
         // returns true if mark() and read() supports
         bool = bis.markSupported();
         System.out.println("Support for mark() and reset() : "+bool);  
      
      } catch(Exception e) {
         e.printStackTrace();
      } finally {
         // releases any system resources associated with the stream
         if(bis!=null)
            bis.close();
         if(inStream!=null)
            inStream.close();
      }
   }
}

假設我們有一個文字檔案c:/test.txt,其內容如下。此檔案將用作示例程式的輸入:

ABCDE 

讓我們編譯並執行上述程式,這將產生以下結果:

Support for mark() and reset() : true
java_io_bufferedinputstream.htm
廣告
© . All rights reserved.