linux 解压后出现乱码怎么办,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

来源:https://www.cnblogs.com/jkmiao/p/5179865.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!你的问题是关于Java解压zip包后出现乱码的问题。在Java中,解压zip文件的主要方式是使用ZipInputStream类。如果出现乱码,可能是因为在解压过程中没有指定正确的字符集编码导致的。下面是一个Java解压zip文件的示例代码: ``` public static void unzip(String zipFilePath, String destDir) throws IOException { byte[] buffer = new byte[1024]; ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFilePath), Charset.forName("GBK")); ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { String fileName = zipEntry.getName(); File newFile = new File(destDir + File.separator + fileName); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); zipEntry = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } ``` 在这个示例中,我们指定了解压文件使用的字符集编码为GBK。这是因为在中文Windows操作系统中,zip文件的默认字符集编码就是GBK。如果你的zip文件使用的是其他字符集编码,你需要相应地更改代码中的字符集编码设置。 另外,如果你的zip文件中包含了压缩前已经出现乱码文件名,那么解压后还是会出现乱码。这是因为文件名的乱码已经被写入到zip文件中了。如果你需要解决这个问题,可以尝试使用ZipFile类来打开zip文件,并使用ZipEntry的getName()方法获取正确的文件名。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值