輸出流 
輸入流 
File類 
1、字節(jié)輸入流類及其子類 之后的代碼重點(diǎn)學(xué)習(xí)文件輸入流和緩沖輸入流,字符輸入流等其他流可以對(duì)比著學(xué)習(xí),基本上是大同小異。
(1)文件輸入流及其常用方法
字節(jié)輸入流之文件輸入流學(xué)習(xí)代碼一package com.imooc.input_output_stream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class FileInputStreamDemo1 { public static void main(String[] args) { //創(chuàng)建一個(gè)FileInputStream對(duì)象 /* * 兩種常用構(gòu)造方法: * public FileInputStream(File file) throws FileNotFoundException * public FileInputStream(String name) throws FileNotFoundException */ try { //由于imooc.txt是存放在這個(gè)工程目錄下的,是相對(duì)路徑,因此直接寫文件名即可 FileInputStream fis=new FileInputStream("imooc.txt"); /* * public int read() throws IOException * ——從此文件輸入流讀取"一個(gè)"字節(jié),返回讀取的字節(jié)數(shù)據(jù). * 注意,讀取一個(gè)字節(jié)后就不會(huì)再讀取這個(gè)字節(jié)了,相當(dāng)于水管中取水滴 * 如果第二遍執(zhí)行read方法那么讀取的就是下一個(gè)字節(jié)了 */ int n; while((n=(fis.read()))!=-1)//讀取的字節(jié)為-1時(shí),說(shuō)明讀到了文件的末尾 { System.out.print((char) n);//將讀到的字節(jié)轉(zhuǎn)換為對(duì)應(yīng)的字符 } /* * public void close() throws IOException * ——關(guān)閉此文件輸入流,并釋放與流相關(guān)聯(lián)的任何系統(tǒng)資源。 * 要養(yǎng)成隨手關(guān)閉輸入流的習(xí)慣 */ fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) //由于FileNotFoundException是IOException的子類,因此IOException要放后面 { e.printStackTrace(); } }}字節(jié)輸入流之文件輸入流學(xué)習(xí)代碼二package com.imooc.input_output_stream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class FileInputStreamDemo2 { public static void main(String[] args) { try { FileInputStream fis=new FileInputStream("imooc.txt"); /* * public int read(byte[] b) throws IOException * ————從該輸入流中最多讀取b.length個(gè)字節(jié)的數(shù)據(jù)并存放在字節(jié)數(shù)組b中,返回實(shí)際讀取的字節(jié)數(shù) * public int read(byte[] b,int off,int len) throws IOException * ————從輸入流中最多讀取len個(gè)字節(jié)的數(shù)據(jù),并將其存放在字節(jié)數(shù)組b中,但放入數(shù)組b中時(shí),從index為off的位置開始放 * 并返回實(shí)際讀取的字節(jié)數(shù) */ byte[] b=new byte[100]; fis.read(b);//等價(jià)于fis.read(b,0,12) //將字節(jié)數(shù)組轉(zhuǎn)換為字符串輸出,利用之前學(xué)過(guò)的String類構(gòu)造方法public String(byte[] bytes) System.out.println(new String(b)); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }}2、字節(jié)輸出流及其子類
(1)、文件輸出流及其常用方法 
3、緩沖流 
二、字符流
字符輸入流和輸出流
由于字符流和字節(jié)流方法基本一致,只有處理數(shù)據(jù)的不同,因此不單獨(dú)寫學(xué)習(xí)代碼了,直接拿出字節(jié)字符轉(zhuǎn)換流的代碼。字節(jié)流轉(zhuǎn)換成字符流。
三、對(duì)象序列化及反序列化 步驟
用到的類 

新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注