文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号...

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;


public class FileSpilte {

	/**
	 * @param args
	 * @throws IOException 
	 */
	/*
	 * 文件分割器,
	 * 一个读取流,相应多个输出流。并且生成的碎片文件都有有序的编号
	 */
	public static void main(String[] args) throws IOException {
        
		 File destdir = new File("teampFile\\filepart");
		 File file = new File("E:\\A-Lin - 给我一个理由忘记.mp3");
		 
	    	fileSplite(file,destdir);
	}

	private static void fileSplite(File file, File destdir) throws IOException {
		
		if(!file.exists()){ 
			throw new RuntimeException(destdir+"文件不存在");
		}
	   
		if(!destdir.exists())
		{
			destdir.mkdirs();
		}
		FileInputStream fis = new FileInputStream(file);
		
		FileOutputStream fos = null;
		
		byte[] buf =new byte[1024*1024];
		int count = 0; 
		int len = 0;
		
		while((len=fis.read(buf))!=-1){ 
			File partfile = new File(destdir,(++count)+".part");
			fos = new FileOutputStream(partfile);
			fos.write(buf,0,len);
			fos.close();
		} 
		Properties prop =new Properties();
		prop.setProperty("partcount",Integer.toString(count));
		prop.setProperty("filename", file.getName());
		
		File profile = new File(destdir,(++count)+".properties");
		fos=new FileOutputStream(profile);
		prop.store(fos, "save");
		
		fos.close();
		
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值