FilterOutputStream類flush()方法
- flush() 方法可在
java.io
包。 - flush() 方法用於刷新此 FilterOutputStream 並強製將字節從任何緩衝數據中寫入 FilterInputStream。
- flush() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- flush() 方法可能會在刷新流時拋出異常。
IOException: 獲取任何輸入/輸出錯誤時可能會拋出此異常。
用法:
public void flush();
參數:
- 它不接受任何參數。
返回值:
該方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void flush() method of FilterInputStream
import java.io.*;
public class FlushOfFOS {
public static void main(String[] args) throws Exception {
FileInputStream fis_stm = null;
FilterInputStream fil_stm = null;
FileOutputStream fos_stm = null;
FilterOutputStream fol_stm = null;
int count = 0;
try {
// Instantiates FileOutputStream and
// FilterOutputStream
fos_stm = new FileOutputStream("D:\\includehelp.txt");
fol_stm = new BufferedOutputStream(fos_stm);
// By using write() method is to
// write byte to the fol_stm stream
fol_stm.write(97);
// By using flush() method is to
// write bytes out to the basic
// output stream
fol_stm.flush();
// Instantiates FileInputStream and
// FilterInputStream
fis_stm = new FileInputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
fil_stm = new BufferedInputStream(fis_stm);
// Loop to read until available
// bytes left
while ((count = fil_stm.read()) != -1) {
// Display corresponding bytes value
char ch = (char) count;
// Display value of b
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 (fis_stm != null) {
fis_stm.close();
if (fil_stm != null) {
fil_stm.close();
if (fol_stm != null) {
fol_stm.close();
if (fos_stm != null) {
fos_stm.close();
}
}
}
}
}
}
}
輸出
ch:a
相關用法
- Java FilterOutputStream close()用法及代碼示例
- Java FilterReader reset()用法及代碼示例
- Java FilterInputStream markSupported()用法及代碼示例
- Java FilterInputStream mark()用法及代碼示例
- Java FilterReader skip()用法及代碼示例
- Java FilterWriter close()用法及代碼示例
- Java FilterInputStream close()用法及代碼示例
- Java FilterInputStream available()用法及代碼示例
- Java FilterReader close()用法及代碼示例
- Java FilterInputStream reset()用法及代碼示例
- Java FilterReader ready()用法及代碼示例
- Java FilterReader markSupported()用法及代碼示例
- Java FilterReader mark()用法及代碼示例
- Java FilterWriter flush()用法及代碼示例
- Java FilterInputStream skip()用法及代碼示例
- Java File isHidden()用法及代碼示例
- Java File renameTo()用法及代碼示例
- Java File setWritable()用法及代碼示例
- Java File listFiles()用法及代碼示例
- Java FileStore getBlockSize()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java FilterOutputStream flush() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。