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();
}
}