unzip 中文乱码的解决方案(linux)

刚开始我们使用的是yum install unzip 安装的是6.0以上版本

unzip  file.zip 全是乱码

接着采用了jar xvf file.zip 报这样的错:

 jar xvf 【推荐课程】初中物理20150413(14个)-未提交\ 已校验完毕.zip 
java.lang.IllegalArgumentException: MALFORMED
        at java.util.zip.ZipCoder.toString(ZipCoder.java:58)
        at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:297)
        at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:121)
        at sun.tools.jar.Main.extract(Main.java:922)
        at sun.tools.jar.Main.run(Main.java:264)
        at sun.tools.jar.Main.main(Main.java:1231)
当然主要的原因是有中文

然后找到了unzip -O PB936 file.zip 的文件

-O PB936 提示PB936 could not find

最后,我们觉得是版本的问题

使用yum erase unzip 卸载了6.0的版本

到unzip官网:http://www.info-zip.org/UnZip.html 下载5.52的版本(/upload/file/2015/06/03/FILE_Jzia_740987689205760.gz

进入unzip目录
#cd unzip-5.52

找到文件 unzpriv.h (修改内容大概在文件末尾),修改以下内容:

/* Convert filename (and file comment string) into "internal" charset.
* This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
* codepage when made on
* -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
* -> OS/2 (FS_HPFS_)
* -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
* EXCEPTIONS:
* PKZIP for Windows 2.5 and 2.6 flag their entries as "FS_FAT_", but the
* filename stored in the local header is coded in Windows ANSI (ISO 8859-1).
* Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
* filenames stored in BOTH the local and the central header are coded
* in the local system's codepage (usually ANSI codings like ISO 8859-1).
*
* All other ports are assumed to code zip entry filenames in ISO 8859-1.
*/
#ifndef Ext_ASCII_TO_Native
# define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
if (((hostnum) == FS_FAT_ && \
!(((islochdr) || (isuxatt)) && \
(hostver) >= 25 && (hostver) <= 26)) || \
(hostnum) == FS_HPFS_ || \
((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
_OEM_INTERN((string)); \
} else { \
_ISO_INTERN((string)); \
}
#endif


注释其他语句,只留_ISO_INTERN((string)),修改如下:

#ifndef Ext_ASCII_TO_Native
# define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
/* if (((hostnum) == FS_FAT_ && \
* !(((islochdr) || (isuxatt)) && \
* (hostver) >= 25 && (hostver) <= 26)) || \
* (hostnum) == FS_HPFS_ || \
* ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
* _OEM_INTERN((string)); \
* } else { \ */
_ISO_INTERN((string)); \
/* } */
#endif

复制unix编译文件到当前目录下
#cp unix/Makefile .

Ubuntu的安装方式

make prefix=/usr linux 

sudo make prefix=/usr install

CentOS的安装方式

make generic  (centos)

make install(centos)

再解压就OK了

草木全
分享到:
共 0 条  此列表为空  当前1/1页

© 2014 究问社区 copyRight 豫ICP备13003319号-1