标签:bsp lin new buffered file color ade 释放 line
一、单字符复制
//明确数据源 FileReader fr=new FileReader("D:\\java1018\\buffer.txt"); //明确目的地 FileWriter fw=new FileWriter("D:\\java1018\\b\\buffer.txt"); //创建字符缓冲流对象 BufferedReader br=new BufferedReader(fr); BufferedWriter bw=new BufferedWriter(fw); //开始复制 int len = 0; while ((line=br.read())!=-1) { bw.write(len); bw.flush(); } //释放资源 br.close(); bw.close();
二、整行复制
//明确数据源 FileReader fr=new FileReader("D:\\java1018\\buffer.txt"); //明确目的地 FileWriter fw=new FileWriter("D:\\java1018\\b\\buffer.txt"); //创建字符缓冲流对象 BufferedReader br=new BufferedReader(fr); BufferedWriter bw=new BufferedWriter(fw); //开始复制 String line=null; while ((line=br.readLine())!=null) { bw.write(line); bw.newLine(); bw.flush(); } //释放资源 br.close(); bw.close();
三、字符数组复制
//明确数据源 FileReader fr=new FileReader("D:\\java1018\\buffer.txt"); //明确目的地 FileWriter fw=new FileWriter("D:\\java1018\\b\\buffer.txt"); //创建字符缓冲流对象 BufferedReader br=new BufferedReader(fr); BufferedWriter bw=new BufferedWriter(fw); //开始复制 char[] ch = new char[1024]; int len = 0; while ((line=br.read(ch))!=-1) { bw.write(line,0,len); bw.flush(); } //释放资源 br.close(); bw.close();
标签:bsp lin new buffered file color ade 释放 line
原文地址:https://www.cnblogs.com/l1314/p/12361511.html