字节输出流

该Java程序展示了如何使用缓冲输入流和缓冲输出流从c:/bbb/12转义字符.mp4复制视频文件到c:/aaa/sb.mp4。程序首先读取源文件到内存缓冲区,然后将缓冲区内容写入目标文件,提高了文件操作效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c:/bbb下面有一个视频文件 复制到c:/aaa下面

使用Java代码

思路: 先从磁盘读取到内存缓冲数组(输入流)中然后再写入磁盘中(输出)

package com.qf.c_zonghe;

import java.io.*;

public class Demo1 {
    public static void main(String[] args) throws IOException {
        copyVideo1();
    }
    public static void copyVideo () throws IOException {
        //创建缓冲输入流对象
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("c:/bbb/12转义字符.mp4")));
        //创建缓冲输出流对象
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("c:/aaa/sb.mp4")));
        //准备一个缓冲数组
        byte[] buf = new byte[4096];
        int length;
        while ((length = bis.read(buf)) != -1) {//length = bis.read(buf)  从磁盘读取数据到缓冲数组中
            bos.write(buf, 0, length);//从缓冲数组中写入到磁盘
        }
        bos.close();
        bis.close();
    }
    //不带缓冲的
    public static void copyVideo1 () throws IOException {
       FileInputStream fis = new FileInputStream(new File("c:/bbb/12转义字符.mp4"));
       FileOutputStream fos = new FileOutputStream(new File("c:/aaa/2b.mp4"));
       int length;
       while ((length = fis.read()) != -1) {
            fos.write(length);
       }
       fos.close();
       fis.close();

    }

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值