开发者

Does creation of new File(filename) object associate a process file descriptor with the object?

Does the following statement:

new File(filename);

associate a process file descriptor with the File object? Tried to search the same but without any success.

Ideally, it should not statically associate the file descriptor with the File object. Whenever,开发者_如何学Go function calls are executed a file descriptor should get associated with the File Object for the period of time when the function call gets executed.

Any help appreciated.


There's no file descriptor, because new File(filename) does not open the file. It's just a easily manipulable representation of a path name.

File descriptors refer to open files. The fact that the file is not opened is not explicitly documented, but it follows from the principle of least surprise and from the fact that no exceptions are listed corresponding to failure to open the file.


No, new File(...) only is an object representing the filename, without even checking that there exists a file (or directory) with this name and/or path.


No. You can see this by examining the source of the File class yourself, from jdk 1.6.0_22:

public File(String pathname) {
    if (pathname == null) {
        throw new NullPointerException();
    }
    this.path = fs.normalize(pathname);
    this.prefixLength = fs.prefixLength(this.path);
}

Since you can call the File constructor with a path that doesn't yet exist, and since File objects can represent non-existent Files, it wouldn't be possible to associate descriptors with it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜