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.
Applications should not create their own file descriptors. 文件描述符是对底层资源(文件、网口接口、其余的一些字节源)的引用,主要用于输入输出流。
应用程序不能进行建立文件描述符对象。(公用的构造函数是无用的,只有私有的告诉函数)
bash
以下图:咱们能够看到文件描述符的与底层文件系统、系统文件管理、进行文件描述符的关系。socket
程序1:函数
1 FileOutputStream file1=new FileOutputStream("zhao.text");
2 FileOutputStream file2=new FileOutputStream("zhao.text");
3 // FileOutputStream file3=new FileOutputStream(file2.getFD());
4 file1.write('a');
5 file1.write('a');
6 file2.write('c');
7 System.out.println(file1.getFD().equals(file2.getFD()));
复制代码
文件内容为ca 输出false 缘由:打开两次相同的文件,从头开始写入。 文件描述符对同一个文件,能够不一样spa
程序2:.net
参考线程