StringBufferInputStream類reset()方法
- reset() 方法可在
java.io
包。 - reset() 方法用於重置此 StringBufferInputStream 並將流重置到 mark() 方法最近設置的位置。
- reset() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- reset() 方法在重置流時不會拋出異常。
用法:
public void reset();
參數:
- 它不接受任何參數。
返回值:
該方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void reset() method of StringBufferInputStream
import java.io.*;
public class ResetOfSBIS {
public static void main(String[] args) throws Exception {
StringBufferInputStream is_stm = null;
int count = 0;
try {
// Instantiates StringBufferInputStream
is_stm = new StringBufferInputStream("Java Programming");
// Loop to read until available
// bytes left
while ((count = is_stm.read()) != -1) {
// Display corresponding char value
char ch = (char) count;
// Display value of ch
System.out.println("ch:" + ch);
// By using skip() method is to
// skip 1 byte of data from the is_stm
// stream
long skip = is_stm.skip(3);
System.out.println("is_stm.skip(1):" + skip);
}
// By using reset() method is to reset
// the stream
System.out.println("is_stm.reset():");
is_stm.reset();
while ((count = is_stm.read()) != -1) {
// Display corresponding char value
char ch = (char) count;
// Display value of ch
System.out.println("ch:" + ch);
}
} catch (Exception ex) {
System.out.println(ex.toString());
} finally {
// with the help of this block is to
// free all necessary resources linked
// with the stream
if (is_stm != null) {
is_stm.close();
}
}
}
}
輸出
ch:J is_stm.skip(1):3 ch: is_stm.skip(1):3 ch:g is_stm.skip(1):3 ch:m is_stm.skip(1):3 is_stm.reset(): ch:J ch:a ch:v ch:a ch: ch:P ch:r ch:o ch:g ch:r ch:a ch:m ch:m ch:i ch:n ch:g
相關用法
- Java StringBufferInputStream available()用法及代碼示例
- Java StringBufferInputStream skip()用法及代碼示例
- Java StringBuffer toString()用法及代碼示例
- Java StringBuffer offsetByCodePoints()用法及代碼示例
- Java StringBuffer ensureCapacity()用法及代碼示例
- Java StringBuffer subSequence()用法及代碼示例
- Java StringBuffer codePointAt()用法及代碼示例
- Java StringBuffer setLength()用法及代碼示例
- Java StringBuffer replace()用法及代碼示例
- Java StringBuffer trimToSize()用法及代碼示例
- Java StringBuffer appendCodePoint()用法及代碼示例
- Java StringBuffer deleteCharAt()用法及代碼示例
- Java StringBuffer getChars()用法及代碼示例
- Java StringBuffer indexOf()用法及代碼示例
- Java StringBuffer reverse()用法及代碼示例
- Java StringBuffer delete()用法及代碼示例
- Java StringBuffer codePointCount()用法及代碼示例
- Java StringBuffer insert()用法及代碼示例
- Java StringBuffer lastIndexOf()用法及代碼示例
- Java StringBuffer deleteCharAt(int index)用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java StringBufferInputStream reset() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。