本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.setPassword方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.setPassword方法的具体用法?Java ZipFile.setPassword怎么用?Java ZipFile.setPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.core.ZipFile
的用法示例。
在下文中一共展示了ZipFile.setPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: unzipfile
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public void unzipfile(File zipfile, String dest, String passwd) throws ZipException {
ZipFile zfile = new ZipFile(zipfile);
// zfile.setFileNameCharset("GBK");//在GBK系统中需要设置
if (!zfile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能已经损坏!");
}
File file = new File(dest);
if (file.isDirectory() && !file.exists()) {
file.mkdirs();
}
if (zfile.isEncrypted()) {
zfile.setPassword(passwd.toCharArray());
}
zfile.extractAll(dest);
}
示例3: decompressZipFile
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public void decompressZipFile(String appName, String filename, String password) {
String filePath = Environment.getExternalStorageDirectory() + "/" + appName;
try {
File src = new File(filePath, filename);
ZipFile zipFile = new ZipFile(src);
if (zipFile.isEncrypted())
zipFile.setPassword(password);
zipFile.extractAll(filePath);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例4: example7
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 示例7 解压压缩文件
*/
@Test
public void example7(){
example4();
try {
ZipFile zipFile = new ZipFile("src/main/resources/AddFilesWithAESZipEncryption.zip");
if (zipFile.isEncrypted()) {
// if yes, then set the password for the zip file
zipFile.setPassword("123456");
zipFile.extractAll("src/main/resources/zipfile");
}
} catch (ZipException e) {
e.printStackTrace();
}
}
示例5: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset("GBK");
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for(FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir,fileHeader.getFileName()));
}
}
File [] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例6: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password) {
try {
ZipFile zipFile = new ZipFile(targetZipFilePath);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destinationFolderPath);
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param zipFile 指定的ZIP压缩文件
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset("GBK");
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for(FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir,fileHeader.getFileName()));
}
}
File [] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例8: decompress
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* Decompress.
*
* @param sourceZipFilePath
* the source zip file path
* @param extractedZipFilePath
* the extracted zip file path
* @param password
* the password
*/
public void decompress(String sourceZipFilePath, String extractedZipFilePath, String password) {
try {
ZipFile zipFile = new ZipFile(sourceZipFilePath);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(extractedZipFilePath);
} catch (Exception e) {
JKExceptionUtil.handle(e);
}
}
示例9: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static File[] unzip(String source, String destination, String password){
try {
ZipFile zipFile = new ZipFile(source);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
}
return listFilesIn(destination);
}
示例10: 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();
}
}
示例11: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param zip 指定的ZIP压缩文件
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
* @throws IOException
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException, IOException {
if(StringUtils.isEmpty(dest))
throw new ZipException("@@@@Error: Unzip destination can not be empty!!!!");
if(zipFile == null || !zipFile.exists())
throw new ZipException("@@@@Error: Unzip file not exist!!!!");
if(AppFileUtils.getContentType(zipFile.getName()).equals("rar")){
return unrar(zipFile,dest);
} else {
File destDir = new File(dest);
FileUtils.forceMkdir(destDir);
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset(Constants.GBK); //不可随意更换位置
if (!zFile.isValidZipFile()) {
throw new ZipException(String.format("@@@@Error: Unzip file: %s is broken!!!!",zipFile.getAbsolutePath()));
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
@SuppressWarnings("unchecked")
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for (FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
File out = new File(destDir, fileHeader.getFileName());
extractedFileList.add(out);
log.debug("File to be extracted....." + out.getAbsolutePath());
}
}
File[] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
}
示例12: unZipFile
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static void unZipFile(String zipFilePath,String sourceFilePath,boolean setPassword,String password) throws Exception {
ZipFile zipFile = new ZipFile(zipFilePath);
if(setPassword){
zipFile.setPassword(password);
}
zipFile.extractAll(sourceFilePath);
}
示例13: BBBEPubZip4J
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public BBBEPubZip4J(String fileUrl, char[] zipPassword) throws ZipException {
mFileUrl = fileUrl;
mZipFile = new ZipFile(fileUrl);
if (mZipFile.isEncrypted()) {
mZipFile.setPassword(zipPassword);
}
}
示例14: unzipFileIntoDirectory
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, String password) throws FermeExceptionNoSpaceLeftOnDevice {
try {
ZipFile zipFile = new ZipFile(zipFileName_);
if (password != null && zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destinationDirectory);
}
catch (ZipException e) {
e.printStackTrace();
return -1;
}
return 0;
}
示例15: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
*
* @param zip
* 指定的ZIP压缩文件
* @param dest
* 解压目录
* @param passwd
* ZIP文件的密码
* @param charset
* ZIP文件的编码
* @return 解压后文件数组
* @throws ZipException
* 压缩文件有损坏或者解压缩失败抛出
*/
public static File[] unzip(File zipFile, String dest, String passwd,
String charset) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
if (null != charset || !"".equals(charset)) {
zFile.setFileNameCharset(charset);
}
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for (FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir, fileHeader
.getFileName()));
}
}
File[] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}