Filedescriptor简述

简介

  • 文件描述符类的官方解释:

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. 进程描述符的文件描述符只是起一个指向做用,文件能够屡次打开,打开的文件指向统一底层。可是文件描述符是不相同的。
  2. 也能够用一个文件描述符,建立多个输入输出流。基本与上一个相同。
  3. 线程有几个特殊的文件描述符,0表明标准输出、1表明标准输入、2表明错误输出。每一个进程都是如此。

程序演示

程序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

文件内容为cca 输出true 缘由:相同的文件描述符,至关于打开同一个文件。可是file1与file3的对象不equal。

参考线程

  1. 其余文献参考orcale的库文件说明 二、图参考https://blog.csdn.net/weixin_34119545/article/details/89038953
相关文章
相关标签/搜索