您当前的位置: 首页 >  小志的博客 Java

java复制文件实例

小志的博客 发布时间:2018-06-19 11:49:56 ,浏览量:4

package com.cn;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStream;

      /**

 * 复制文件类
 * 创建者    :  xxx
 * 创建日期: 2018年06月12日
 */

public class copyFileTest{

      /**

* 复制文件
* 创建者    :  xxx
* 创建日期: 2018年06月12日
* @param fromFile //源文件路径
* @param toFile //新文件路径
* @throws IOException 异常
*/
public static boolean copyFile(File fromFile,File toFile) throws IOException{
        FileInputStream ins = new FileInputStream(fromFile);
        FileOutputStream out = new FileOutputStream(toFile);
        byte[] b = new byte[1024];
        int n=0;
        while((n=ins.read(b))!=-1){
            out.write(b, 0, n);
        }
        
        ins.close();
        out.close();

}

}

关注
打赏
查看更多评论

小志的博客

暂无认证

  • 4浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录