Java Code Examples for net.lingala.zip4j.model.ZipParameters#setRootFolderInZip()
The following examples show how to use
net.lingala.zip4j.model.ZipParameters#setRootFolderInZip() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 添加文件夹到zip中 * @data 2017年4月18日 * @param inPath * @param storagePath * @param outPath * @param password * @return */ public static boolean addFoldInZip(String inPath,String storagePath,String outPath,String password) { try { ZipFile zipFile = new ZipFile(outPath); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); parameters.setRootFolderInZip(storagePath); ; if(password!=null&&!password.equals("")){ parameters.setEncryptFiles(true); parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); parameters.setPassword(password); } zipFile.addFolder(inPath, parameters); return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 2
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 添加文件到zip中指定的文件夹中 * @param inPath * @param storagePath * @param outPath * @param password * @return */ public static boolean addFileInZip(String inPath,String storagePath,String outPath,String password) { try { ZipFile zipFile = new ZipFile(outPath); File inFile = new File(inPath); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); parameters.setRootFolderInZip(storagePath); if(password!=null&&!password.equals("")){ parameters.setEncryptFiles(true); parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); parameters.setPassword(password); } zipFile.addFile(inFile, parameters); return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 3
Source File: ZipUtil.java From MonitorClient with Apache License 2.0 | 6 votes |
/** * 添加多个文件到zip中指定的文件夹中 * @param inPath * @param storagePath * @param outPath * @param password * @return */ public static boolean addFilesInZip(ArrayList<File> inFiles,String storagePath,String outPath,String password) { try { ArrayList filesToAdd = new ArrayList(); ZipFile zipFile = new ZipFile(outPath); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); parameters.setRootFolderInZip(storagePath); if(password!=null&&!password.equals("")){ parameters.setEncryptFiles(true); parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); parameters.setPassword(password); } zipFile.addFiles(inFiles, parameters); return true; } catch (ZipException e) { e.printStackTrace(); return false; } }
Example 4
Source File: GenerateFinalZip.java From apk-decompiler with GNU General Public License v2.0 | 6 votes |
private void generateZipFile() { try { File outputFile = new File(this.workFolder.getName() + ".zip"); if (outputFile.exists()) { Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting."); outputFile.delete(); } ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile); Logger.info("Generating " + output.getFile().getAbsolutePath()); ZipParameters params = new ZipParameters(); params.setIncludeRootFolder(false); params.setRootFolderInZip(""); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params); params.setRootFolderInZip("classes"); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params); } catch (Throwable t) { Logger.error("Unable to generate final zip file.", t); } }
Example 5
Source File: GenerateFinalZip.java From apk-decompiler with GNU General Public License v2.0 | 6 votes |
private void generateZipFile() { try { File outputFile = new File(this.workFolder.getName() + ".zip"); if (outputFile.exists()) { Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting."); outputFile.delete(); } ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile); Logger.info("Generating " + output.getFile().getAbsolutePath()); ZipParameters params = new ZipParameters(); params.setIncludeRootFolder(false); params.setRootFolderInZip(""); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params); params.setRootFolderInZip("classes"); output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params); } catch (Throwable t) { Logger.error("Unable to generate final zip file.", t); } }
Example 6
Source File: Zip4j.java From maven-framework-project with MIT License | 6 votes |
/** * 示例2 创建压缩包添加文件到指定目录中进行压缩 */ @Test public void example2(){ try { ZipFile zipFile = new ZipFile("src/main/resources/AddFilesDeflateComp.zip"); ArrayList<File> filesToAdd = new ArrayList<File>(); filesToAdd.add(new File("src/main/resources/sample.txt")); filesToAdd.add(new File("src/main/resources/zip4j.txt")); filesToAdd.add(new File("src/main/resources/zip4j-1.3.2.jar")); ZipParameters parameters = new ZipParameters(); parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); parameters.setRootFolderInZip("target/"); zipFile.addFiles(filesToAdd, parameters); } catch (ZipException e) { e.printStackTrace(); } }