为什么java.io.File没有close()方法? [英] Why java.io.File doesn't have a close() method?

查看:463
本文介绍了为什么java.io.File没有close()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.io.RandomAccessFile 确实有一个 close()方法 java。 io.File 不。这是为什么?是文件自动关闭finalization或什么?



谢谢!

解决方案

File 类的javadoc将类描述为:


摘要文件和目录路径名的表示。

文件只是一个路径名的表示,文件系统(如 exists())和目录处理,但实际的流输入和输出在其他地方完成。可以打开和关闭流,文件不能。

(我个人认为,Sun很遗憾继续创建 RandomAccessFile 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:

An abstract representation of file and directory pathnames.

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()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆