java解压中文乱码
① java压缩中文zip,系统winrar解压改中文zip会出现乱码
建议 使用 apache ant 工具包来做压缩,能完美的解决中文乱码问题
② java中jar打包后中文文件全部乱码,如何解决
打包的问题吧,重新打包,你看打包完的jar文件当然是乱码了
1.建立MANIFEST.MF
(在D:\abc目录下)
以下内容为文件内容
(只复制2行等于号之间的)
==================
Manifest-Version:
1.0
Main-Class:
RoundButton
Created-By:
Abc
==================
2.打包
把你的RoundButton.class复制到D:\abc目录下
然后
开始--》运行--》敲cmd打开命令行,
输入cd
d:\abc
回车
输入d:
回车
输入jar
cvfm
abc.jar
MANIFEST.MF
*.*
回车
然后就能看到abc目录下有个叫abc.jar的文件,双击可以运行,jar包名字随便改,不影响
以上操作前提条件是你机器里jdk环境变量配置正确,100%可用,我已经试过
③ 如何解决java程序解压含有中文名的zip压缩包出现乱码
上次利用java自动的java.util.zip.ZipEntry和�0�2java.util.zip.ZipFile来解压zip文件,今天发现程序在读取解压文件时居然报了空指针异常,debug程序后发现时读取不到文件,产生原先是zip压缩文件中含有中文的名称,读取文件名为乱码,
报找不到文件名,所以报了空指针,想到ant构建文件也有这个功能,换了apache的ant.jar居然解决了中文的问题。
备份下。
�0�2import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;/*** 读取zip压缩文件中文本的内容
* @author fish*/public class ReadZip {
public static void main(String args[]) {try {String fileName = "D:/workspace/java/src/ReadZip.zip";
//构造ZipFile
ZipFile zf = new ZipFile(new File(fileName));
//返回 ZIP file entries的枚举.
Enumeration<? extends ZipEntry entries = zf.getEntries();
while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement();
System.out.println("name:"+ze.getName());
long size = ze.getSize();
if (size 0) {
System.out.println("Length is " + size);
BufferedReader br = new BufferedReader(
new InputStreamReader(zf.getInputStream(ze)));
String line;
while ((line = br.readLine()) != null) {
④ 通过java控制linux环境下解压文件夹后中文文件名是乱码
将linux当前环境设置为中文环境即可。
修改/etc/sysconfig/i18n 文件
LANG="zh_CN.GB2312"
⑤ 请大神帮忙解决一个用java解压缩一个zip压缩格式字节流中文内容乱码问题!
这个问题我有点印象,好像是包的问题。好像不能用zip的那个,换另一个包就好了。具体我也不记得了
⑥ 如何解决Java中的中文乱码问题
如果你的项目编码是utf-8的话,右键项目properties-->Resource-->others 下拉框改为utf-8。望采纳:)
⑦ java用apache的ZipEntry压缩文件名为中文的word文件时,文件名乱码
apache自带的zip方法有缺陷,没有做中文的判断的,这个是它的一个已知bug。
解决办法:用jdk的rt.jar里面的方法实现就可以了。
可以参考下以下工具类:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
*
* @author gdb
*/
public class ZipUtilAll {
public static final int DEFAULT_BUFSIZE = 1024 * 16;
/**
* 解压Zip文件
*
* @param srcZipFile
* @param destDir
* @throws IOException
*/
public static void unZip(File srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/**
* 解压Zip文件
*
* @param srcZipFile
* @param destDir
* @throws IOException
*/
public static void unZip(String srcZipFile, String destDir) throws IOException
{
ZipFile zipFile = new ZipFile(srcZipFile);
unZip(zipFile, destDir);
}
/**
* 解压Zip文件
*
* @param zipFile
* @param destDir
* @throws IOException
*/
public static void unZip(ZipFile zipFile, String destDir) throws IOException
{
Enumeration<? extends ZipEntry> entryEnum = zipFile.entries();
ZipEntry entry = null;
while (entryEnum.hasMoreElements()) {
entry = entryEnum.nextElement();
File destFile = new File(destDir + entry.getName());
if (entry.isDirectory()) {
destFile.mkdirs();
}
else {
destFile.getParentFile().mkdirs();
InputStream eis = zipFile.getInputStream(entry);
System.out.println(eis.read());
write(eis, destFile);
}
}
}
/**
* 将输入流中的数据写到指定文件
*
* @param inputStream
* @param destFile
*/
public static void write(InputStream inputStream, File destFile) throws IOException
{
BufferedInputStream bufIs = null;
BufferedOutputStream bufOs = null;
try {
bufIs = new BufferedInputStream(inputStream);
bufOs = new BufferedOutputStream(new FileOutputStream(destFile));
byte[] buf = new byte[DEFAULT_BUFSIZE];
int len = 0;
while ((len = bufIs.read(buf, 0, buf.length)) > 0) {
bufOs.write(buf, 0, len);
}
} catch (IOException ex) {
throw ex;
} finally {
close(bufOs, bufIs);
}
}
/**
* 安全关闭多个流
*
* @param streams
*/
public static void close(Closeable... streams)
{
try {
for (Closeable s : streams) {
if (s != null)
s.close();
}
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
}
}
/**
* @param args
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
// unZip(new File(ZipDemo.class.getResource("D:/123/HKRT-B2B.zip").toURI()), "D:/123/");
unZip("D:/123/123.zip", "D:/123/");
// new File();
}
}
⑧ 如何解决Java项目中的中文乱码
设置工作空间的编码:
编辑器的编码会影响到所有的项目中的字符的显示,可以说是作用最为广泛的设置,每一个项目都会受到这个设置的影响。点击菜单栏中的窗口(Window)— —选项(Preferences)。
点击常规(General)— —工作空间(Wordspace),然后在右侧的文本文件编码格式(Text file encoding)中选择你想要设置的编码格式,系统默认的格式为GBK。
设置项目的编码:
如果其他的项目中不存在乱码问题,只是个别项目显示时出现乱码,那么我们不需要设置工作空间的编码,只需要修改项目的编码即可。
选中项目后,右键点击,在弹出的菜单中点击属性(Properties)。
在弹出的属性窗口中,选择资源(Resource)— —点击选择Other(其他),然后选择你想要的编码格式。
设置单个文件的编码:
只是个别文件出现了乱码,那么设置个别文件的编码格式就可以解决问题了。选中有乱码的文件,然后点击右键。
在弹出的菜单中选择属性(Properties)。
在弹出的属性窗口中选择资源,点击Other(其他)后设置个别文件的编码方式
⑨ 用java直接读取zip类型的文件时中文乱码问题怎么解决
1.一般是软件程序解码错误。如浏览器把GBK码当成是Big5码显示,或电子邮件程序把对方传来的邮件错误解码。如果在发送时编码错误,收件者的电邮程序是不能解码的,需要寄件者的电邮程序重新编码再寄。
2.字体档案(font file)不对。
3.来源编码错误,或文件受到破坏。
4.一种语言版本的操作系统安装了另外一种语言版本的应用程序,或者应用程序安装的升级补丁的语言版本与应用程序原来安装的语言版本不一致。
5.早期单字节的应用程序在打开双字节语言的文件时不能正确识别文字的分割,在换行的地方把一个字从中分成两段,导致紧接在后面的整个一行全部都是乱码。
6.低版本的应用程序不能识别高版本的程序创建的文件。
7.由于TXD等修改文件出现内部冲突,一些修改游戏的MOD(modification)CLEO、IV补丁、真实补丁、技能补丁、升级补丁和CCI人物补丁等游戏修改软件的“Readme”“必看!”等阅读文件会出现乱码。