当前位置: 首页>>代码示例>>Java>>正文


Java ZipFile.extractFile方法代码示例

本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.extractFile方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.extractFile方法的具体用法?Java ZipFile.extractFile怎么用?Java ZipFile.extractFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.lingala.zip4j.core.ZipFile的用法示例。


在下文中一共展示了ZipFile.extractFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ExtractSingleFile

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public ExtractSingleFile() {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractSingleFile.zip");
		
		// Check to see if the zip file is password protected 
		if (zipFile.isEncrypted()) {
			// if yes, then set the password for the zip file
			zipFile.setPassword("test123!");
		}
		
		// Specify the file name which has to be extracted and the path to which
		// this file has to be extracted
		zipFile.extractFile("Ronan_Keating_-_In_This_Life.mp3", "c:\\ZipTest\\");
		
		// Note that the file name is the relative file name in the zip file.
		// For example if the zip file contains a file "mysong.mp3" in a folder 
		// "FolderToAdd", then extraction of this file can be done as below:
		zipFile.extractFile("FolderToAdd\\myvideo.avi", "c:\\ZipTest\\");
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:27,代码来源:ExtractSingleFile.java

示例2: ExtraFromZIP

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public ExtraFromZIP(String strZIP) {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\JBox\\ZIP\\" + strZIP + ".zip");
		
		// Extracts all files to the path specified under the file name folder
		//zipFile.extractAll("c:\\JBox\\UNZIP\\" + strZIP.substring(0, strZIP.indexOf(".")));
		
		// Specify the file name which has to be extracted and the path to which
		// this file has to be extracted
		zipFile.extractFile(strZIP, "c:\\JBox\\UNZIP\\");
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:chianingwang,项目名称:JBox,代码行数:19,代码来源:ExtraFromZIP.java

示例3: withData

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private void withData() throws Exception {
    FileUtil fileUtil = new FileUtil();
    File dataFile = new File(fileUtil.getBaseFolderName() + "data.zip");
    dataZip = new ZipFile(dataFile);
    if (dataZip.getFileHeaders() != null) {
        List fileHeaderList = dataZip.getFileHeaders();
        ProgressModel progressModel = new ProgressModel();
        progressModel.setMax(fileHeaderList.size());
        publishProgress(progressModel);
        List<FileHeader> headers = dataZip.getFileHeaders();
        for (FileHeader header : headers) {
            dataZip.extractFile(header, fileUtil.getBaseFolderName());
            copyFileToData(fileUtil.getBaseFolderName(), header.getFileName());
        }
    }
    FileUtils.forceDelete(dataFile);
}
 
开发者ID:k0shk0sh,项目名称:KAM,代码行数:18,代码来源:RestoreAppsTasker.java

示例4: descompact

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
@Override
public String descompact(String in) throws IOException {

    String name = CompressionUtils.getName(in).replace(".zip4j", "");
    String folder = CompressionUtils.getParentFolder(in);

    try {

        ZipFile zipFile = new ZipFile(in);
        zipFile.extractFile(name, folder);

    } catch (ZipException e) {
        throw new IOException(e);
    }
    return folder + "/" + name;
}
 
开发者ID:bionimbuz,项目名称:Bionimbuz,代码行数:17,代码来源:Zip4JCompactor.java

示例5: repackCert

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * Jar sign creates CERT SF & RSA but some apk have different name like
 * ABC.SF This module will rename the CERT.SF & CERT.RSA to the new
 * certificate name
 * 
 * @param newAPKPath
 *            Path of the modified apk
 */
public static void repackCert(String newAPKPath) {

	try {
		ZipFile zipFile = new ZipFile(newAPKPath);
		zipFile.extractFile("META-INF" + File.separator + "CERT.RSA",
				getProjectPath());
		zipFile.extractFile("META-INF" + File.separator + "CERT.SF",
				getProjectPath());
		zipFile.removeFile("META-INF" + File.separator + "CERT.SF");
		zipFile.removeFile("META-INF" + File.separator + "CERT.RSA");
		File rsaFile = new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + "CERT.RSA");
		File sfFile = new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + "CERT.SF");
		File newCertFolder = new File(getProjectPath() + File.separator
				+ "META-INF");
		rsaFile.renameTo(new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + certificateName + ".RSA"));
		sfFile.renameTo(new File(getProjectPath() + File.separator
				+ "META-INF" + File.separator + certificateName + ".SF"));
		ZipParameters parameters = new ZipParameters();
		parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
		parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
		zipFile.addFolder(newCertFolder, parameters);

	} catch (ZipException e) {
		e.printStackTrace();
	}
}
 
开发者ID:csanuragjain,项目名称:APKRepatcher,代码行数:38,代码来源:Utility.java

示例6: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 解压指定文件
 *
 * @param zip
 * @param fileHeader
 * @param destPath
 * @return
 */
public static boolean unzip(ZipFile zip, FileHeader fileHeader, File destPath){
    try {
        zip.extractFile(fileHeader, destPath.getAbsolutePath());
        return true;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:18,代码来源:ZipUtils.java

示例7: ExtractByLoopAllFiles

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public ExtractByLoopAllFiles() {
	
	try {
		// Initiate ZipFile object with the path/name of the zip file.
		ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractByLoopAllFiles.zip");
		
		// Check to see if the zip file is password protected 
		if (zipFile.isEncrypted()) {
			// if yes, then set the password for the zip file
			zipFile.setPassword("test123!");
		}
		
		// Get the list of file headers from the zip file
		List fileHeaderList = zipFile.getFileHeaders();
		
		// Loop through the file headers
		for (int i = 0; i < fileHeaderList.size(); i++) {
			FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
			// Extract the file to the specified destination
			zipFile.extractFile(fileHeader, "c:\\ZipTest\\");
		}
		
	} catch (ZipException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:28,代码来源:ExtractByLoopAllFiles.java

示例8: getJsonFromZip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private String getJsonFromZip(String path){
	try {
		ZipFile zipFile = new ZipFile(path);
		//con.log("Log",path.substring(path.lastIndexOf('/') + 1).replace(".zip","") + "/info.json");
		zipFile.extractFile(path.substring(path.lastIndexOf('/') + 1).replace(".zip","") + "/info.json", System.getProperty("java.io.tmpdir"));
	} catch (ZipException e) {
		con.log("Severe","Failed to unzip from getJsonFromZip");
	}
	return null;
}
 
开发者ID:Fireblade,项目名称:McLauncher,代码行数:11,代码来源:Utility.java

示例9: extract

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
@Override
public void extract(File zip, String fileName, File destination, String password)
        throws ZipException {
    try {
        ZipFile zipFile = new ZipFile(zip);
        if ((password != null) && zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        zipFile.extractFile(fileName, destination.getAbsolutePath());
    } catch (net.lingala.zip4j.exception.ZipException e) {
        throw new ZipException(e);
    }
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:14,代码来源:ZipDelegaterZip4j.java

示例10: getProjectFolderName

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private String getProjectFolderName(File projectZipFile, int max_lenght_folder_name) throws ZipException, IOException {
	ZipFile zipFile = new ZipFile(projectZipFile);
	File definitionFolder = new File(EarthConstants.GENERATED_FOLDER);
	zipFile.extractFile( PROJECT_PROPERTIES_FILE_NAME, definitionFolder.getAbsolutePath() );		
	String projectName =  getProjectSurveyName(new File( definitionFolder + File.separator + PROJECT_PROPERTIES_FILE_NAME) );
	
	projectName = StringUtils.remove(projectName, " "); //$NON-NLS-1$
	
	if( projectName.length() > max_lenght_folder_name ){
		projectName = projectName.substring(0, max_lenght_folder_name);
	}
	
	return projectName;

}
 
开发者ID:openforis,项目名称:collect-earth,代码行数:16,代码来源:EarthProjectsService.java

示例11: extractFileFromZip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static boolean extractFileFromZip(File zip, String fileName, File outputLocation) {
	try {
		ZipFile zipFile = new ZipFile(zip);
		zipFile.extractFile(fileName, outputLocation.getPath());
		return true;
	} catch (ZipException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:Watchful1,项目名称:PermissionsChecker,代码行数:11,代码来源:FileUtils.java

示例12: doInBackground

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
@Override
    protected ProgressModel doInBackground(Context... params) {
        try {
            FileUtil fileUtil = new FileUtil();
            boolean withData = AppHelper.isRestoreData(params[0]);
            if (withData) RootManager.getInstance().obtainPermission();
            File zipFile = new File(fileUtil.getBaseFolderName() + "backup.zip");
            if (!zipFile.exists()) {
//                if (withData) {
//                    withData();
//                }
                return error("Backup Folder Doe Not Exits!");
            }
            zFile = new ZipFile(zipFile);
            List fileHeaderList = zFile.getFileHeaders();
            ProgressModel progressModel = new ProgressModel();
            progressModel.setMax(fileHeaderList.size());
            publishProgress(progressModel);
            for (int i = 0; i < fileHeaderList.size(); i++) {
                if (isCancelled()) {
                    return error("cancelled");
                }
                FileHeader fileHeader = (FileHeader) fileHeaderList.get(i);
                zFile.extractFile(fileHeader, fileUtil.getBaseFolderName());
                progressModel = new ProgressModel();
                progressModel.setProgress(i);
                progressModel.setFileName(fileHeader.getFileName());
                publishProgress(progressModel);
                if (AppHelper.isRoot()) {
                    Result result = AppHelper.installApkSilently(new File(fileUtil.getBaseFolderName() + fileHeader.getFileName()).getPath());
                    if (result != null && result.getStatusCode() == Result.ResultEnum.INSTALL_SUCCESS.getStatusCode()) {
                        boolean deleteApk = new File(fileUtil.getBaseFolderName() + fileHeader.getFileName()).delete();
                    }
                } else {
                    progressModel.setFilePath(fileUtil.getBaseFolderName() + fileHeader.getFileName());
                }
            }
            zipFile.delete();
        } catch (Exception e) {
            e.printStackTrace();
            return error(e.getMessage());
        }
        return null;
    }
 
开发者ID:k0shk0sh,项目名称:KAM,代码行数:45,代码来源:RestoreAppsTasker.java

示例13: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static void unzip(File zipArchive, File destinationDirectory, @Nullable FileFilter skipFilter)
        throws IOException {
    try {
        FileUtil.ensureDirectoryExists(destinationDirectory);
        ZipFile zipFile = new ZipFile(zipArchive);

        int count = 0;

        for (Object fileHeader : zipFile.getFileHeaders()) {
            if (count >= MAX_ZIP_ENTRY_COUNT) {
                break;
            }

            FileHeader entry = (FileHeader) fileHeader;
            File file = new File(destinationDirectory, entry.getFileName());
            if (skipFilter != null && skipFilter.accept(file)) {
                continue;
            }

            if (entry.isDirectory()) {
                FileUtil.ensureDirectoryExists(file);
            } else {
                long maxSize = max(entry.getUncompressedSize(), entry.getCompressedSize());

                if (maxSize <= MAX_ZIP_ENTRY_SIZE) {
                    FileUtil.ensureDirectoryExists(file.getParentFile());
                    zipFile.extractFile(entry, destinationDirectory.getAbsolutePath());
                } else {
                    throw new IOException(String.format(
                            "Entry '%s' (%s) is larger than %s.",
                            entry.getFileName(), FileUtil.formatSize(maxSize),
                            FileUtil.formatSize(MAX_ZIP_ENTRY_SIZE)
                    ));
                }
            }

            ++count;
        }
    } catch (ZipException e) {
        throw new IOException("Can't extract ZIP-file to directory.", e);
    }
}
 
开发者ID:Codeforces,项目名称:codeforces-commons,代码行数:43,代码来源:ZipUtil.java


注:本文中的net.lingala.zip4j.core.ZipFile.extractFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。