Why doesn't java.io.File have a close method?

后端 未结 5 2019
不知归路
不知归路 2020-11-29 23:53

While java.io.RandomAccessFile does have a close() method java.io.File doesn\'t. Why is that? Is the file closed automatically on fina

5条回答
  •  醉话见心
    2020-11-30 00:06

    Say suppose, you have

    File f  = new File("SomeFile");
    f.length();
    

    You need not close the Files, because its just the representation of a path.

    You should always consider to close only reader/writers and in fact streams.

提交回复
热议问题