簡體   English   中英

Java關閉BufferedReader,Scanner和FileReader

[英]Java closing BufferedReader, Scanner and FileReader

在我的程序中,我解析文件。 我這樣打開它們:

Scanner s = new Scanner(new BufferedReader(new FileReader("file1.txt")));

然后關閉它:

s.close();

我的問題是:當我執行s.close() ,這也會關閉FileReader和BufferedReader嗎?

Java醫生說

public void close()

Closes this scanner.

If this scanner has not yet been closed then if its underlying readable also implements the Closeable interface then the readable's close method will be invoked. If this scanner is already closed then invoking this method will have no effect.

Attempting to perform search operations after a scanner has been closed will result in an IllegalStateException. 

由於BufferedReader已實現Closeable ,因此它將調用緩沖區讀取器關閉方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM