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 !!!");
    }
}

方法二: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 = file.read(name)
    if not os.path.exists(utf8name):
        fo = open(utf8name, "w")
        fo.write(data)
        fo.closefile.close()
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,239评论 25 709
  • 飘飘落落,往往习习,我好似在那不远之处又见到了你。 忆记童年时光的繁阴,似流水般地涌上心头。我在外面呼唤着你,两...
    隔壁老周7阅读 2,325评论 0 0
  • 豪车超跑鬼见愁!只有国产车能这么霸气 秋名山车神?面包车的领军人物?豪车终结者?没错你没有猜错!是它是它就是它我们...
    再见无效阅读 2,920评论 0 0
  • 雷雁雄3月8日总结:祝各位女神节日快乐!今天开车回昆明,春暖花开,一路都是那样春意盎然,美一直都存在,只是有时行色...
    雷雁雄阅读 1,751评论 0 0
  • 文本 文本阴影 文本轮廓 基本上浏览器不支持 换行 word-break:属性规定自动换行的处理方法 word-w...
    greenteaObject阅读 2,532评论 0 1

友情链接更多精彩内容