中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

做眾籌網(wǎng)站需要什么條件以服務營銷出名的企業(yè)

做眾籌網(wǎng)站需要什么條件,以服務營銷出名的企業(yè),學院網(wǎng)站建設意義,四川建設工程網(wǎng)最近項目中有個需求需要對文件夾進行壓縮后傳輸,考慮數(shù)據(jù)泄露安全性問題,需要對壓縮包進行加密,特地查找了下開源壓縮加密類庫,找到了Java語言開發(fā)的zip4j庫,覺得挺好用的,在這分享給大家! Jav…

? ? ? ?最近項目中有個需求需要對文件夾進行壓縮后傳輸,考慮數(shù)據(jù)泄露安全性問題,需要對壓縮包進行加密,特地查找了下開源壓縮加密類庫,找到了Java語言開發(fā)的zip4j庫,覺得挺好用的,在這分享給大家!

Java項目引入使用步驟如下:

1、引入maven依賴

<dependency>
? ? ? ? ? ? <groupId>net.lingala.zip4j</groupId>
? ? ? ? ? ? <artifactId>zip4j</artifactId>
? ? ? ? ? ? <version>2.11.5</version>
?</dependency>

2、封裝的工具類

import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.AesKeyStrength;
import net.lingala.zip4j.model.enums.CompressionLevel;
import net.lingala.zip4j.model.enums.CompressionMethod;
import net.lingala.zip4j.model.enums.EncryptionMethod;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
?* @desc zip解壓縮工具
?* @author: wcy
?* @date: 2024/1/12
?* @version: 1.0
?*/
public class ZipUtil {
? ? private static final Logger log = LoggerFactory.getLogger(ZipUtil.class);

? ? /**
? ? ?* 壓縮指定路徑的文件
? ? ?* @param srcFilePath 待壓縮文件路徑
? ? ?* @param zipPathFileName zip文件全路徑名
? ? ?* @param password 加密密碼
? ? ?* @return
? ? ?*/
? ? public static boolean zipFile(String srcFilePath, String zipPathFileName, String password){

? ? ? ? try {
? ? ? ? ? ? // 生成的壓縮文件
? ? ? ? ? ? ZipFile zipFile = new ZipFile(zipPathFileName);
? ? ? ? ? ? if (StringUtils.isNotEmpty(password)) {
? ? ? ? ? ? ? ? zipFile.setPassword(password.toCharArray());
? ? ? ? ? ? }
? ? ? ? ? ? ZipParameters parameters = new ZipParameters();
? ? ? ? ? ? // 壓縮級別
? ? ? ? ? ? parameters.setCompressionMethod(CompressionMethod.DEFLATE);
? ? ? ? ? ? parameters.setCompressionLevel(CompressionLevel.NORMAL);

? ? ? ? ? ? if(StringUtils.isNotEmpty(password)){
? ? ? ? ? ? ? ? parameters.setEncryptFiles(true);
? ? ? ? ? ? ? ? parameters.setEncryptionMethod(EncryptionMethod.AES);
? ? ? ? ? ? ? ? parameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
? ? ? ? ? ? }

? ? ? ? ? ? // 要打包的文件夾
? ? ? ? ? ? File file = new File(srcFilePath);
? ? ? ? ? ? if (file.isDirectory()) {
? ? ? ? ? ? ? ? zipFile.addFolder(file, parameters);
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? zipFile.addFile(file, parameters);
? ? ? ? ? ? }
? ? ? ? ? ? return true;
? ? ? ? } catch (ZipException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? log.error("壓縮文件【"+srcFilePath+"】到路徑【"+zipPathFileName+"】失敗:\n"+e.getMessage());
? ? ? ? ? ? return false;
? ? ? ? }
? ? }

? ? /**
? ? ?* ?@param zipFileFullName zip文件所在的路徑名
? ? ?* @param filePath 解壓到的路徑
? ? ?* @param password 需要解壓的密碼
? ? ?* @return
? ? ?*/
? ? public static boolean unZipFile(String zipFileFullName, String filePath, String password) {
? ? ? ? try {
? ? ? ? ? ? ZipFile zipFile = new ZipFile(zipFileFullName);
? ? ? ? ? ? // 如果解壓需要密碼
? ? ? ? ? ? if(StringUtils.isNotEmpty(password) && zipFile.isEncrypted()) {
? ? ? ? ? ? ? ? zipFile.setPassword(password.toCharArray());
? ? ? ? ? ? }
? ? ? ? ? ? zipFile.extractAll(filePath);
? ? ? ? ? ? return true;
? ? ? ? } catch (ZipException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? log.error("解壓文件【"+zipFileFullName+"】到路徑【"+filePath+"】失敗:\n"+e.getMessage());
? ? ? ? ? ? return false;
? ? ? ? }
? ? }

? ? /**
? ? ?* 添加文件到壓縮文件中
? ? ?* @param zipFullFileName zip文件所在路徑及全名
? ? ?* @param fullFileNameList 待添加的文件全路徑集合
? ? ?* @param rootFolderInZip 在壓縮文件里的文件夾名
? ? ?* @return
? ? ?*/
? ? public static boolean addFilesToZip(String zipFullFileName, List<String> fullFileNameList, String rootFolderInZip) {
? ? ? ? try {
? ? ? ? ? ? ZipFile zipFile = new ZipFile(zipFullFileName);
? ? ? ? ? ? ArrayList<File> addFiles = new ArrayList<>();
? ? ? ? ? ? for (String fileName : fullFileNameList) {
? ? ? ? ? ? ? ? addFiles.add(new File(fileName));
? ? ? ? ? ? }

? ? ? ? ? ? ZipParameters parameters = new ZipParameters();
? ? ? ? ? ? parameters.setCompressionMethod(CompressionMethod.DEFLATE);
? ? ? ? ? ? parameters.setCompressionLevel(CompressionLevel.NORMAL);
? ? ? ? ? ? if(StringUtils.isNotEmpty(rootFolderInZip)){
? ? ? ? ? ? ? ? if(!rootFolderInZip.endsWith("/")){
? ? ? ? ? ? ? ? ? ? rootFolderInZip = rootFolderInZip+"/";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? parameters.setRootFolderNameInZip(rootFolderInZip);
? ? ? ? ? ? }
? ? ? ? ? ? zipFile.addFiles(addFiles, parameters);
? ? ? ? ? ? return true;
? ? ? ? } catch (ZipException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? log.error("添加文件失敗:\n"+e.getMessage());
? ? ? ? ? ? return false;
? ? ? ? }
? ? }

? ? /**
? ? ?* 從壓縮文件中刪除路徑
? ? ?* @param zipFullFileName
? ? ?* @param fileName
? ? ?* @return
? ? ?*/
? ? public static boolean deleteFileInZip(String zipFullFileName, String fileName) {
? ? ? ? try {
? ? ? ? ? ? ZipFile zipFile = new ZipFile(zipFullFileName);
? ? ? ? ? ? zipFile.removeFile(fileName);
? ? ? ? ? ? return true;
? ? ? ? } catch (ZipException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? ? ? log.error("刪除文件失敗:\n"+e.getMessage());
? ? ? ? ? ? return false;
? ? ? ? }
? ? }

? ? public static void main(String[] args) throws ZipException {
? ? ? ? String srcFilePath = "C:\\Users\\test\\Desktop\\project\\video";
? ? ? ? String desFilePath = "C:\\Users\\test\\Desktop\\project\\file";
? ? ? ? String zipPathFileName = "C:\\Users\\test\\Desktop\\project\\video.zip";
? ? ? ? String password = "";
? ? ? ? long begin = System.currentTimeMillis();
? ? ? ? boolean zipResult = zipFile(srcFilePath, zipPathFileName, password);
? ? ? ? long end = System.currentTimeMillis();
? ? ? ? System.out.println("壓縮結果:" + zipResult + ",耗時:" + (end - begin) + "ms");

? ? ? ? boolean unZipResult = unZipFile(zipPathFileName, desFilePath, password);
? ? ? ? long end2 = System.currentTimeMillis();
? ? ? ? System.out.println("解壓結果:" + unZipResult + ",耗時:" + (end2 - end) + "ms");
? ? ? ? System.out.println(unZipResult);
? ? }
}

3、測試結果

壓縮結果:true,耗時:3281ms
解壓結果:true,耗時:590ms

http://www.risenshineclean.com/news/45370.html

相關文章:

  • 鄭州注冊公司網(wǎng)站視頻seo優(yōu)化教程
  • 德州極速網(wǎng)站建設百家號專業(yè)培訓心得體會
  • 覺 網(wǎng)站廣州seo優(yōu)化公司
  • wordpress取消置頂seo優(yōu)化公司排名
  • wap手機網(wǎng)站建設制作開發(fā)深圳競價排名網(wǎng)絡推廣
  • 廣州番禺建網(wǎng)站什么是seo關鍵詞優(yōu)化
  • 資源交易網(wǎng)站代碼百度經(jīng)驗手機版
  • 星裕建設網(wǎng)站朝陽seo搜索引擎
  • 南昌公司做網(wǎng)站南京百度seo排名優(yōu)化
  • 網(wǎng)站建設可行分析性報告真正永久免費的建站系統(tǒng)有哪些
  • 千牛cdn wordpress長沙網(wǎng)站優(yōu)化推廣方案
  • 免費網(wǎng)站建站一級av無代碼免費web開發(fā)平臺
  • wordpress主題樣式seo軟件資源
  • 挖礦網(wǎng)站怎么做seo技術培訓寧波
  • 郴州百度seoseo入門教學
  • 國內(nèi)網(wǎng)站不備案品牌推廣的方式有哪些
  • 今天八點發(fā)布的株洲疫情網(wǎng)站搜索引擎優(yōu)化主要方法
  • 網(wǎng)站圖片鏈接到視頻怎么做微信營銷推廣
  • 婚慶公司加盟連鎖品牌廣告優(yōu)化
  • 哪個網(wǎng)站專門做母嬰東營網(wǎng)站推廣公司
  • 上海app制作灰色行業(yè)seo
  • 自己建一個網(wǎng)站難嗎網(wǎng)站怎么營銷推廣
  • 五合一小程序網(wǎng)站推廣網(wǎng)站排名
  • 四川網(wǎng)站建設套餐北京網(wǎng)站seo設計
  • ppt做雜志模板下載網(wǎng)站搜索引擎排行榜前十名
  • 免費的黃岡網(wǎng)站有哪些代碼系統(tǒng)優(yōu)化的意義
  • 把網(wǎng)站傳到服務器上怎么做新媒體運營
  • 做網(wǎng)站是怎樣賺錢深圳全網(wǎng)營銷哪里好
  • 網(wǎng)站的排名優(yōu)化怎么做怎么做網(wǎng)頁設計的頁面
  • js網(wǎng)站模板下載軟文推廣例子