zoukankan      html  css  js  c++  java
  • 文件分割器,一个读取流,相应多个输出流,并且生成的碎片文件都有有序的编号

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

  • 相关阅读:
    Dialog 对话框的文字与输入框不对齐
    ag-grid动态生成表头及绑定表数据
    ag-grid实时监测复选框变化
    Java-分页工具类
    Java-日期转换工具类
    文件上传与下载
    IDEA的安装与激活
    熟悉IDEA工具的使用
    缓存三大问题的解决办法
    制作一个省份的三级联动菜单
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5396974.html
Copyright © 2011-2022 走看看