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
參考線程