本帖最后由 高一航 于 2013-1-6 00:34 编辑
画了一张图,送给Writer,FileWriter,FileOutputStream,OutputStreamWriter,BufferedWriter,BufferedOutputStream傻傻分不清楚的同学!!
红色的是字符流路线,蓝色的是字节流路线,绿色的是字节转流字符流的路线(实现文件转码,读一行数据,等功能..) 希望帮的到大家 , 有错的地方请多指教!
鼠标单击 看大图:
Google Drive原图 : https://docs.google.com/drawings/d/1fWtmOunGp98mKQeN5QKCfAI8ZkVmNamfVVYjaD4HayU/edit
附字节流转字符流实现代码:- FileInputStream fis = new FileInputStream(fileA);
- InputStreamReader isr = new InputStreamReader(fis,"utf-8");
- BufferedReader br= new BufferedReader(isr);
- FileOutputStream fos=new FileOutputStream(fileB);
- OutputStreamWriter osr=new OutputStreamWriter(fos,"GBK");
- BufferedWriter bw=new BufferedWriter(osr);
- String buf;
- while((buf=br.readLine())!=null){
- bw.write(buf);
- bw.newLine();
- }
复制代码 |