linux下zip文件解壓后亂碼解決方案


 

解決辦法一,利用pyton來處理

1.vi uzip文件
2.復制一下內容(Python)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# uzip.py
 
import os
import sys
import zipfile
 
print "Processing File " + sys.argv[1]
 
file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
    utf8name=name.decode('gbk')
    print "Extracting " + utf8name
    pathname = os.path.dirname(utf8name)
    if not os.path.exists(pathname) and pathname!= "":
        os.makedirs(pathname)
    data = file.read(name)
    if not os.path.exists(utf8name):
        fo = open(utf8name, "w")
        fo.write(data)
        fo.close
file.close()

 

3.chmod +x uzip
4../uzip xxxx.zip

 

方法2,通過unzip行命令解壓,指定字符集(推薦使用)
 

unzip -O CP936 xxx.zip (用GBK, GB18030也可以)

有趣的是unzip的manual中並無這個選項的說明,unzip –help對這個參數有一行簡單的說明。

方法3,在環境變量中,指定unzip參數,總是以指定的字符集顯示和解壓文件

/etc/environment中加入2行 

UNZIP=”-O CP936″
ZIPINFO=”-O CP936″

方法4,采用java的jar命令解壓zip包 JAR 解壓

jar xvf file.name


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM