本文整理匯總了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();
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
}