国产18禁黄网站免费观看,99爱在线精品免费观看,粉嫩metart人体欣赏,99久久99精品久久久久久,6080亚洲人久久精品

2017年計(jì)算機(jī)二級(jí)考試java章節(jié)輔導(dǎo):輸入流

時(shí)間:2017-06-15 15:51:00   來源:無憂考網(wǎng)     [字體: ]

9.5 輸入流

  InputStream SequenceInputStream FileInputStream PipedInputStream ByteArrayInputStream FileterInputStream StringBufferInputStream

  DataInputStream LineNumberInputStream PushbackInputStream BufferedInputStream 有好幾個(gè)類是專門用來處理文件輸入的。下面是文件輸入類的層次結(jié)構(gòu):

  9.5.1 FileInputStream 對(duì)象

  FileInputStream典型地表示一種順序訪問的文本文件。通過使用FileInputStream你可以訪問文件的一個(gè)字節(jié)、幾個(gè)字節(jié)或整個(gè)文件。

  9.5.2 打開FileInputStream

  為一個(gè)文件打開輸入流FileInputStream,你必須將文件名或文件對(duì)象傳送給結(jié)構(gòu):

  FileInputStream myFileStream;

  myFileStream = new FileInputStream ( "/etc/motd");

  你還可以象下邊這樣從FileInputStream里讀文件信息:

  File myFile ;

  FileInputSteam myFileStream;

  myFile = new File("/etc/motd");

  myFileStream = new FileInputStream(myFile);

  FileInputStream輸入流打開,你就可以從里面讀取信息了。read()成員函數(shù)有以下幾種選項(xiàng):

  int read(); //reads one byte //return -1 at end of stream

  int read(byte b[]); //fills entire array,if possible //returns number of bytes read //returns -1 if end of stream is reached

  int read(byte b[],int offset, int len)

  //reads len bytes into b starting at b[offset]

  //Returns number of bytes read,

  //or -1 if end of stream is reached.

  9.5.3 關(guān)閉FileInputStream

  當(dāng)你完成一個(gè)文件的操作,你可選兩種方法關(guān)閉它: 顯式關(guān)閉和隱式關(guān)閉,隱式關(guān)閉是自動(dòng)垃圾回收時(shí)的功能。

  顯式關(guān)閉如下:myFileStream.close();