Java中的IO流(1)

來源:互聯網
上載者:User

標籤:利用   input   sha   output   close   緩衝區   檔案路徑   stream   序列化   

位元組流://一個位元組一個位元組的讀寫FileInputStream in=new FileInputStream("源檔案");FileOutputStream out=new FileOutputStream("目標檔案");......in.close();out.close();首先要記住,一旦使用了IO流最後一定要記得關閉,這是常識。//利用緩衝區,高效的讀取位元組BufferedInputStream in=new BufferedInputStream(new FileInputStream("源檔案");BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream("目標檔案");......in.close();out.close();字元流:InputStreamReader isr=new InputStreamReader(new FileInputStream("源檔案路徑"),"設定編碼");OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("目標檔案路徑"),"設定編碼");......osw.close();isr.close();也可以這樣寫:FileReader fr=new FileReader("源檔案路徑");FileWriter fw=new FileWriter("目標檔案路徑");......fr.close();fw.close();//利用緩衝區,高效的讀取字元BufferedReader br=new BufferedReader(new FileReade("源檔案路徑");PrintWriter pw=new PrintWriter("目標檔案路徑");......br.close();pw.close();序列化和還原序列化://對象的序列化ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(file));這裡的file指的是String file="檔案在項目中的路徑";//對象的還原序列化ObjectInputStream ois=new ObjectInputStream(new FileInputStream(file));

  

Java中的IO流(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.