zoukankan      html  css  js  c++  java
  • 文件的切割和合并

    package test;
     
     
    import java.io.*;
    import java.sql.SQLClientInfoException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.zip.InflaterInputStream;
     
    import javax.annotation.processing.FilerException;
    import javax.management.RuntimeErrorException;
    
    import privateclass.Filterby_Name;
    import privateclass.Filterby_hidden;
    import privateclass.Filterby_java;
    import privateclass.MyBufferedReader;
     
    public class Main {
     
        private static final String space_operator = " ";
        private static final double pi = Math.PI;
        private static final String LINE_SEPARATOR = System.getProperty("line.separator");
    	private static final int SIZE = 1024*1024;
        public static void main(String[] args) throws Exception {
     
        	
        	File file = new File("D:\1.png");
        	File file2 = new File("d:\图片分割");
        	//cutting(file);
        	mergepart(file2);
        	
        	
        }
    	/**
               *文件切割
         * @throws IOException 
         */
    	public static void cutting(File file) throws IOException {
    		FileInputStream fis = new FileInputStream(file);
    		byte buf[] = new byte[SIZE];
    		int len = 0;
    		int count = 1;
    		FileOutputStream fos = null;
    		File dirFile = new File("d:\图片分割");
    		if(!dirFile.exists())dirFile.mkdirs();
    		while((len = fis.read(buf)) != -1)
    		{
    			fos = new FileOutputStream(new File(dirFile,(count++) + ".part"));
    			fos.write(buf, 0, len);
    		}
    		fis.close();
    		fos.close();
    	}
       
    	public static void mergepart(File file2) throws IOException {
    		List<FileInputStream> list = new ArrayList<FileInputStream>();
    		for(int i = 1; i <= file2.listFiles().length; i ++)
    		{
    			list.add(new FileInputStream(new File(file2,i + ".part")));
    		}
    		
    		Enumeration<FileInputStream> en = Collections.enumeration(list);
    		SequenceInputStream sis = new SequenceInputStream(en);
    		FileOutputStream fos = new FileOutputStream(new File(file2,"1.png"));
    		byte buf [] = new byte[SIZE];
    		int len = 0;
    		while((len = sis.read(buf)) != -1)
    		{
    			fos.write(buf,0,len);
    		}
    		sis.close();
    		fos.close();
    		
    	}
    }
    

      

  • 相关阅读:
    CF 980D Perfect Groups(数论)
    CF 983B XOR-pyramid(区间dp,异或)
    CF 984C Finite or not? (数论)
    CF 979D Kuro and GCD and XOR and SUM(异或 Trie)
    (可能)常用打比赛网站
    排序工作量之新任务(SHOI2001)
    【图楼】长期图楼~~不定期更新
    【题解】SHOI2014概率充电器
    【题解】NOIP2015推销员
    [NOI2015][bzoj4197] 寿司晚宴 [状压dp+质因数]
  • 原文地址:https://www.cnblogs.com/WINDZLY/p/11826231.html
Copyright © 2011-2022 走看看