文件复制——视频复制

文件复制——视频复制


文件复制

package cn.itcast_04;

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

/*
 * 需求:把c:\\a.txt内容复制到d:\\b.txt中
 * 
 * 数据源:
 * 		c:\\a.txt	--	读取数据	--	FileInputStream
 * 目的地:
 * 		d:\\b.txt	--	写出数据	--	FileOutputStream
 */
public class CopyFileDemo {
	public static void main(String[] args) throws IOException {
		// 封装数据源
		FileInputStream fis = new FileInputStream("c:\\a.txt");
		FileOutputStream fos = new FileOutputStream("d:\\b.txt");

		// 复制数据
		byte[] bys = new byte[1024];
		int len = 0;
		while ((len = fis.read(bys)) != -1) {
			fos.write(bys, 0, len);
		}

		// 释放资源
		fos.close();
		fis.close();
	}
}

视频复制

package cn.itcast_04;

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

/*
 * 需求:把e:\\哥有老婆.mp4复制到当前项目目录下的copy.mp4中
 * 
 * 数据源:
 * 		e:\\哥有老婆.mp4--读取数据--FileInputStream
 * 目的地:
 * 		copy.mp4--写出数据--FileOutputStream
 */
public class CopyMp4Demo {
	public static void main(String[] args) throws IOException {
		// 封装数据源
		FileInputStream fis = new FileInputStream("e:\\哥有老婆.mp4");
		// 封装目的地
		FileOutputStream fos = new FileOutputStream("copy.mp4");

		// 复制数据
		byte[] bys = new byte[1024];
		int len = 0;
		while ((len = fis.read(bys)) != -1) {
			fos.write(bys, 0, len);
		}

		// 释放资源
		fos.close();
		fis.close();
	}
}



猜你喜欢

转载自blog.csdn.net/cmm0401/article/details/80465108