博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
将A文件的内容复制到B文件
阅读量:4221 次
发布时间:2019-05-26

本文共 1511 字,大约阅读时间需要 5 分钟。

private static void fileCopy1(File from, File to){        InputStream in = null;        OutputStream out = null;        try{            //定义高效字节流            in = new BufferedInputStream(new FileInputStream(from));            out = new BufferedOutputStream(new FileOutputStream(to));            //传输            int b = 0;            while((b = in.read())!=-1){                out.write(b);            }        }catch(Exception e){            e.printStackTrace();        }finally{            try{                assert in != null;                in.close();                assert out != null;                out.close();            }catch(Exception e){                e.printStackTrace();            }finally{                in = null;                out = null;            }        }    }    // 使用字符流复制,只能复制文本文件    private static void fileCopy2(File from,File to){        Reader r = null;        Writer w= null;        try{            r = new BufferedReader(new FileReader(from));            w = new BufferedWriter(new FileWriter(to));            int b = 0;            while((b = r.read())!=-1){                w.write(b);            }        }catch(Exception e){            e.printStackTrace();        }finally{            try{                assert r != null;                r.close();                assert w != null;                w.close();            }catch(Exception e){                e.printStackTrace();            }finally{                r = null;                w = null;            }        }    }

 

转载地址:http://ubmmi.baihongyu.com/

你可能感兴趣的文章
阶段性胜利。。
查看>>
有点儿累了,最近特别能吃
查看>>
project的架构模式
查看>>
总结一下细节问题
查看>>
重新整合了一下代码
查看>>
有点儿伤感。。
查看>>
我要开始疯狂code了。。。
查看>>
在写我的论坛ing...
查看>>
页面间的信息传递
查看>>
进入了比较困难的阶段
查看>>
初见成效
查看>>
于根伟退役了。。
查看>>
大年初一的晚上
查看>>
接近尾声咯
查看>>
。。。。。。。。。。
查看>>
你还是杀了我吧
查看>>
这个旋律。。
查看>>
这些是我没有好好珍惜的。。
查看>>
2006年2月9日 凌晨0点46分
查看>>
技术文章
查看>>