Java使用缓冲数组分割,合并文件

这篇博客介绍了如何使用Java进行文件的分割和合并操作。在分割文件的过程中,详细阐述了方法;而在合并文件部分,特别指出该方法适用于10个以内文件的合并,若超过10个文件,则需要先对文件名排序以确保数据正确性。
摘要由CSDN通过智能技术生成


首先,进行文件分割

		File savePath = new File("Part");
		 File moveFile = new File("001.mp4");
		 cutFile(savePath, moveFile);

	private static void cutFile(File parent, File file) throws IOException {
		if (!file.exists()) {
			System.out.println("文件不存在");
			return;
		}
		parent.mkdirs();
		// 使用缓冲装饰类来读取视频文件数据
		BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream(file));
		// 创建一个字节缓冲数组
		byte[] buff = new byte[1024 * 1024 * 10];
		int num = 0;
		int i = 1;
		while ((num = buffIn.read(buff)) != -1) {
			File saveP = new File(parent, i + ".part");
			FileOutputStream out = new FileOutputStream(saveP);
			i++;
			out.write(buff, 0, num);
			out.flush();
			out.close();
		}
		Properties pro = new Properties();
		pro.setProperty("filename", file.getName());
		pro.setProperty("partCount", i + "");
		FileOutput
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值