JAVA 2013. 8. 21. 22:23

하나의 파일로 압축하는건 많은데

파일들을 분할 압축하는거는 없다.


zip4j 오랫동안 찾다가 이제 찾음


http://www.lingala.net/zip4j/


소스 정말 심플함.


/*

* Copyright 2010 Srikanth Reddy Lingala  

* Licensed under the Apache License, Version 2.0 (the "License"); 

* you may not use this file except in compliance with the License. 

* You may obtain a copy of the License at 

* http://www.apache.org/licenses/LICENSE-2.0 

* Unless required by applicable law or agreed to in writing, 

* software distributed under the License is distributed on an "AS IS" BASIS, 

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

* See the License for the specific language governing permissions and 

* limitations under the License. 

*/


package net.lingala.zip4j.examples.zip;


import java.io.File;

import java.util.ArrayList;


import net.lingala.zip4j.core.ZipFile;

import net.lingala.zip4j.exception.ZipException;

import net.lingala.zip4j.model.ZipParameters;

import net.lingala.zip4j.util.Zip4jConstants;


/**

 * Demonstrated how to create a split zip file

 * 

 * @author Srikanth Reddy Lingala

 *

 */

public class CreateSplitZipFile {

public CreateSplitZipFile() {

try {

// Initiate ZipFile object with the path/name of the zip file.

ZipFile zipFile = new ZipFile("c:\\ZipTest\\CreateSplitZipFile.zip");

// Build the list of files to be added in the array list

// Objects of type File have to be added to the ArrayList

ArrayList filesToAdd = new ArrayList();//압출할 파일 대상들.

filesToAdd.add(new File("c:\\ZipTest\\sample.txt"));

filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));

filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));

// Initiate Zip Parameters which define various properties such

// as compression method, etc.

ZipParameters parameters = new ZipParameters();

// set compression method to store compression

parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);

// Set the compression level. This value has to be in between 0 to 9

parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

// Create a split file by setting splitArchive parameter to true

// and specifying the splitLength. SplitLenth has to be greater than

// 65536 bytes

// Please note: If the zip file already exists, then this method throws an 

// exception

zipFile.createZipFile(filesToAdd, parameters, true, 10485760);//파일 사이즈 byte단위

} catch (ZipException e) {

e.printStackTrace();

}

}

/**

* @param args

*/

public static void main(String[] args) {

new CreateSplitZipFile();

}


}




posted by 나는너의힘
: