Java中BufferedInputStream類的markSupported()方法用於驗證輸入流是否支持mark和reset方法。如果輸入流不支持這兩種方法中的任何一種,則程序將返回false或true。
用法:
public boolean markSupported()
參數:此方法不接受任何參數。
返回值:此方法返回一個布爾值,指示mark和reset方法的可支持性。
覆蓋:該方法被FilterInputStream類中的markSupported覆蓋。
異常:此方法不會引發任何異常。
以下示例程序旨在說明IO包中BufferedInputStream類中的markSupported()方法:
程序1:假設存在文件“c:/demo.txt”。
// Java program to illustrate
// BufferedInputStream markSupported() method
import java.io.*;
public class GFG {
public static void main(String[] args)
{
// Create input stream 'demo.txt'
// for reading containing text "GEEKS"
FileInputStream inputStream
= new FileInputStream(
"c:/demo.txt");
// Convert inputStream to
// bufferedInputStream
BufferedInputStream buffInputStr
= new BufferedInputStream(
inputStream);
// Returns true if mark()
// and reset () supports
boolean bool
= buffInputStr
.markSupported();
System.out.println(
"Support for mark()"
+" and reset():"
+ bool);
}
}
輸出:
Support for mark() and reset():true
程序2:假設存在文件“c:/demo.txt”。
// Java program to illustrate
// BufferedInputStream.markSupported() method
import java.io.*;
public class GFG {
public static void main(String[] args)
{
// Create input stream 'demo.txt'
// for reading containing text "MRNOTSUPP"
FileInputStream inputStream
= new FileInputStream("c:/demo.txt");
// Convert inputStream to
// bufferedInputStream
BufferedInputStream buffInputStr
= new BufferedInputStream(inputStream);
// Returns false if mark()
// and reset () not supported
boolean bool
= buffInputStr.markSupported();
System.out.println(
"Support for mark()"
+" and reset():"
+ bool);
}
}
輸出:
Support for mark() and reset():false
參考文獻: https://docs.oracle.com/javase/10/docs/api/java/io/BufferedInputStream.html#markSupported()
相關用法
- Java BufferedInputStream close()用法及代碼示例
- Java BufferedInputStream mark()用法及代碼示例
- Java CharArrayReader markSupported()用法及代碼示例
- Java StringReader markSupported()用法及代碼示例
- Java ByteArrayInputStream markSupported()用法及代碼示例
- Java Reader markSupported()用法及代碼示例
- Java PushbackReader markSupported()用法及代碼示例
- Java BufferedInputStream skip(long)用法及代碼示例
- Java BufferedInputStream available()用法及代碼示例
- Java Java.io.BufferedInputStream用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
注:本文由純淨天空篩選整理自pp_pankaj大神的英文原創作品 BufferedInputStream markSupported() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。