标签:
1、输入流、输出流
2、字节流、字符流
3、节点流、处理流
字节流:InputStream OutputStream
字节流:小数据读写;字符流:大文件读写;
try{ FileInputStream fis = new FileInputStream("from.txt"); FileOutputStream fos = new FileOutputStream("to.txt"); byte[] buffer = new byte[1024]; while(true){ int temp = fis.read(buffer,0,buffer.length); if(temp == -1){ break; } fos.write(buffer,0,temp); } }catch(Exception e){ System.out.println(e); }finally{ try{ fis.close(); fos.close(); } catch(Exception e){ System.out.println(e); } }
处理流
try{ FileReader fr = new FileReader ("from.txt"); BufferedReader bf = new BufferedReader(fr ); FileWriter fw = new FileWriter ("to.txt"); BufferedWriter bw= new BufferedWriter(fw ); while(true){ stirng line = br.readLLine(); if(line == null){ break; } bw.writeLine(); } }catch(Exception e){ System.out.println(e); }finally{ try{ BufferedReader.close(); BufferedWriter.close(); FileReader.close(); FileWriter.close(); } catch(Exception e){ System.out.println(e); } }
标签:
原文地址:http://www.cnblogs.com/zengneng/p/5597235.html