PipedReader類close()方法
- close() 方法可在
java.io
包。 - close() 方法用於關閉此 PipedReader 流並釋放與該流鏈接的所有係統資源。
- close() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- close() 方法可能會在關閉流時拋出異常。
IOException: 獲取任何輸入/輸出錯誤時可能會拋出此異常。
用法:
public void close();
參數:
- 它不接受任何參數。
返回值:
該方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void close() method of PipedReader
import java.io.*;
public class CloseOfPR {
public static void main(String[] args) throws Exception {
int val = 65;
try {
// Instantiates PipedReader and PipedWriter
PipedWriter pipe_w = new PipedWriter();
PipedReader pipe_r = new PipedReader();
for (int i = 0; i < 3; ++i) {
// By using write() method is to
// write the val to the stream pipe_w
pipe_w.write(val);
val++;
}
// By using close() method is to close
// the stream
pipe_w.close();
pipe_w.close();
// When we call read() method after closing the
// stream will result an exception
for (int i = 0; i < 3; ++i) {
// By using read() method is to
// read the integer and convert it into
// char
char ch = (char) pipe_r.read();
System.out.println("pipe_r.read():" + ch);
}
} catch (Exception ex) {
System.out.println("Stream Closed Before!!!!");
}
}
}
輸出
Stream Closed Before!!!!
相關用法
- Java PipedReader connect()用法及代碼示例
- Java PipedReader ready()用法及代碼示例
- Java PipedOutputStream connect()用法及代碼示例
- Java PipedOutputStream close()用法及代碼示例
- Java PipedWriter connect()用法及代碼示例
- Java PipedWriter flush()用法及代碼示例
- Java PipedInputStream connect()用法及代碼示例
- Java PipedOutputStream flush()用法及代碼示例
- Java PipedWriter close()用法及代碼示例
- Java PipedInputStream close()用法及代碼示例
- Java PipedInputStream available()用法及代碼示例
- Java PipedInputStream receive()用法及代碼示例
- Java PriorityQueue size()用法及代碼示例
- Java PushbackReader skip()用法及代碼示例
- Java PriorityBlockingQueue peek()用法及代碼示例
- Java Package getAnnotationsByType()用法及代碼示例
- Java PriorityBlockingQueue take()用法及代碼示例
- Java PriorityBlockingQueue iterator()用法及代碼示例
- Java PriorityBlockingQueue add()用法及代碼示例
- Java Path toAbsolutePath()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java PipedReader close() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。