java字节流复制文件

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.junit.Test;

public class JavaIO {

    @Test
    public void test() throws Exception{
        //1、输入输出路径
        String inputPath = "C:\\Users\\zwx474555\\Desktop\\E04D24C1-BB2F-424A-AD2D-7B770C96F9A1.png";  //图片路径
        String outPath = "F:\\123.png";  //复制路径及文件名
        
        //2、输入输出流对象
        FileInputStream fis = new FileInputStream(inputPath);
        FileOutputStream fos = new FileOutputStream(outPath);
        
        //3、声明字节数组,每次按1K读取,按1K输出
        byte[] bytes = new byte[1024];
        
        int temp = 0;
        while((temp = fis.read(bytes)) != -1){
            fos.write(bytes, 0, temp); //一边读取,一边输出
        }
        //4、刷新输出流
        fos.flush();
        
        //5、关闭流
        fis.close();
        fos.close();
        
    }
}

 

转载于:https://www.cnblogs.com/StanLong/p/6931656.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值