把文件abc.txt复制一份名为demo.txt的文件
package .zzx.file;import java.io.*;public class BufferedDemo {public static void main(String[] args) throws Exception {File f1 = new File("D:/demo.txt"); // 写入数据File f2 = new File("D:/abc.txt"); //读取数据InputStream read = new FileInputStream(f2); OutputStream write = new FileOutputStream(f1);//放到缓存区BufferedInputStream br = new BufferedInputStream(read);BufferedOutputStream bw = new BufferedOutputStream(write);byte [] b = new byte[1024];int len = 0;//循环读取,读完返回负1while((len=br.read(b))!=-1){//边读边写bw.write(b, 0,len);}bw.flush();//强制刷新缓冲区bw.close(); //关闭写出流br.close();//关闭读入流}}
更多推荐
缓冲区,Java,File
发布评论