简体   繁体   English

Java中FileDescriptor类及其in,out和err方法的用途是什么?

[英]What's the use of FileDescriptor class in Java and its in,out and err methods?

What's the use of the FileDescriptor class in Java ? Java中FileDescriptor类的用途是什么? We can only obtain it with the getFD() methods on streams and then we can use the obtained FD to create another instance of, say, FileInputStream which we can also do by creating a FileInputStream object with the same file name (instead of using its FD). 我们只能使用流上的getFD()方法获取它,然后可以使用获取的FD创建FileInputStream的另一个实例,也可以通过创建具有相同文件名的FileInputStream对象来实现(而不是使用它的FD)。

Also, the methods in, out and err. 另外,方法in,out和err。 what use can they be put to ? 它们有什么用?

As the JavaDoc says: 正如JavaDoc所说:

Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. 文件描述符类的实例充当基础机器特定结构的不透明句柄,这些结构表示打开的文件,打开的套接字或其他字节源或宿。 The main practical use for a file descriptor is to create a FileInputStream or FileOutputStream to contain it. 文件描述符的主要实际用途是创建一个FileInputStream或FileOutputStream来包含它。

Applications should not create their own file descriptors. 应用程序不应创建自己的文件描述符。

They are therefore a behind-the-scenes implementation detail for the JDK to plug in to the underlying OS 因此,它们是JDK 插入底层操作系统的幕后实现细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM