本文介绍了为什么java.io.File没有close()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
code>,导致与命名不一致的混淆。)While java.io.RandomAccessFile does have a close() method java.io.File doesn't. Why is that? Is the file closed automatically on finalization or something?
Thanks!
解决方案
The javadoc of the File class describes the class as:
File is only a representation of a pathname, with a few methods concerning the filesystem (like exists()) and directory handling but actual streaming input and output is done elsewhere. Streams can be opened and closed, files cannot.
(My personal opinion is that it's rather unfortunate that Sun then went on to create RandomAccessFile, causing much confusion with its inconsistent naming.)
这篇关于为什么java.io.File没有close()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!