linux|linux 解压zip中文乱码问题

本文用程序解决的的,有兴趣可以看一看,limux有解决中文乱码问题,,请去其他博客。
方法一:使用java

importjava.io.File; importjava.io.FileOutputStream; importjava.io.IOException; importjava.io.InputStream; importjava.util.Enumeration; importorg.apache.tools.zip.ZipEntry; importorg.apache.tools.zip.ZipFile; classUnZip{ public static void main(String[] args) throws IOException { //1.找到目录下需要解压的文件String fileAddress = "××××××"; //压缩文件的源位置String unZipAddress = "××××××"; //解压文件的目的位置File file = new File(fileAddress); ZipFile zipFile = null; try { zipFile = new ZipFile(file,"GBK"); //设置编码格式} catch (IOException exception) { exception.printStackTrace(); System.out.println("解压文件不存在!"); }//2.对文件处理Iterator e = (Iterator)zipFile.getEntries(); //迭代处理压缩文件里面的文件while(e.hasNext()) { ZipEntry zipEntry = (ZipEntry)e.next(); if(zipEntry.isDirectory()) {//如果文件存在,按照压缩文件名字,创建压缩文件String name = zipEntry.getName(); name = name.substring(0,name.length()-1); File f = new File(unZipAddress + name); f.mkdirs(); } else {//如果文件不存在,创建新的文件File f = new File(unZipAddress + zipEntry.getName()); f.getParentFile().mkdirs(); f.createNewFile(); InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(f); int length = 0; byte[] b = new byte[1024]; int i=0; //解压输出到文件中,并在界面上打印进度while((length=is.read(b, 0, 1024))!=-1) { fos.write(b, 0, length); i++; System.err.print("#"); //用错误输出流打印#符} is.close(); //关闭Io流fos.close(); } } //关闭文件和删除压缩包if (zipFile != null) { zipFile.close(); } file.deleteOnExit(); //解压完以后将压缩包删除System.out.println("\n This file has unziped ,congraduation !!!"); } }

【linux|linux 解压zip中文乱码问题】方法二:python代码
import sys import zipfileprint "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 = https://www.it610.com/article/file.read(name) if not os.path.exists(utf8name): fo = open(utf8name,"w") fo.write(data) fo.closefile.close()

    推荐阅读