当前位置:首页 » 文件管理 » javazip解压中文

javazip解压中文

发布时间: 2022-12-14 11:41:01

① 请大神帮忙解决一个用java压缩一个zip压缩格式字节流中文内容乱码问题!

这个问题我有点印象,好像是包的问题。好像不能用zip的那个,换另一个包就好了。具体我也不记得了

② 如何在java中实现对zip和rar文件的解压

java中有zip包,可以使用

publicvoidgetZipFiles(StringzipFile,StringdestFolder)throwsIOException{
BufferedOutputStreamdest=null;
ZipInputStreamzis=newZipInputStream(
newBufferedInputStream(
newFileInputStream(zipFile)));
ZipEntryentry;
while((entry=zis.getNextEntry())!=null){
System.out.println("Extracting:"+entry.getName());
intcount;
bytedata[]=newbyte[BUFFER];

if(entry.isDirectory()){
newFile(destFolder+"/"+entry.getName()).mkdirs();
continue;
}else{
intdi=entry.getName().lastIndexOf('/');
if(di!=-1){
newFile(destFolder+"/"+entry.getName()
.substring(0,di)).mkdirs();
}
}
FileOutputStreamfos=newFileOutputStream(destFolder+"/"
+entry.getName());
dest=newBufferedOutputStream(fos);
while((count=zis.read(data))!=-1)
dest.write(data,0,count);
dest.flush();
dest.close();
}
}

rar的只能用第三方api,比如junrar

https://github.com/edmund-wagner/junrar

③ java压缩中文zip,系统winrar解压改中文zip会出现乱码

建议 使用 apache ant 工具包来做压缩,能完美的解决中文乱码问题

④ java压缩zip文件中文乱码问题

我以前也遇到过这个问题,最后发现java自带的zip压缩没办法解决中文名乱码的问题
你可以使用apache ant的zip类(package: org.apache.tools.zip)来解决这个问题。

⑤ 用java直接读取zip类型的文件时中文乱码问题怎么解决

1.一般是软件程序解码错误。如浏览器把GBK码当成是Big5码显示,或电子邮件程序把对方传来的邮件错误解码。如果在发送时编码错误,收件者的电邮程序是不能解码的,需要寄件者的电邮程序重新编码再寄。
2.字体档案(font file)不对。
3.来源编码错误,或文件受到破坏。
4.一种语言版本的操作系统安装了另外一种语言版本的应用程序,或者应用程序安装的升级补丁的语言版本与应用程序原来安装的语言版本不一致。
5.早期单字节的应用程序在打开双字节语言的文件时不能正确识别文字的分割,在换行的地方把一个字从中分成两段,导致紧接在后面的整个一行全部都是乱码。
6.低版本的应用程序不能识别高版本的程序创建的文件。
7.由于TXD等修改文件出现内部冲突,一些修改游戏的MOD(modification)CLEO、IV补丁、真实补丁、技能补丁、升级补丁和CCI人物补丁等游戏修改软件的“Readme”“必看!”等阅读文件会出现乱码。

⑥ java解压zip文件

不好意思搞反了,这样就更简单了。
用这个构造方法ZipInputStream(InputStream in);接收传过来的流,然后用这个类的getNextEntry()方法解压缩文件,最后调用read(byte[] b, int off, int len)方法将数据写入byte数组。
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry = null;
while((entry=zin.getNextEntry())!=null){
if(entry.isDirectory()||entry.getName().equals("..\\"))
continue;
BufferedInputStream bin = new BufferedInputStream(zin);
byte[] buf = new byte[];
bin.read(buf,0,1);
}

⑦ 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程序解压含有中文名的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 解压zip中文文件保存

用jdk自带的zip工具做压缩时,对中文支持不是很好。
建议使用ant.jar中的压缩和解压缩工具

⑩ java zip文件解压

len = zin.read(buff) 不要用 zin,用entry里的

热点内容
数据库约束是什么 发布:2025-09-20 12:14:07 浏览:739
我的世界统一验证服务器 发布:2025-09-20 11:51:59 浏览:187
dialogandroid 发布:2025-09-20 11:32:18 浏览:472
手机软件用什么服务器 发布:2025-09-20 11:26:35 浏览:361
搜索php内容 发布:2025-09-20 11:25:05 浏览:226
python的quote 发布:2025-09-20 11:07:56 浏览:338
vb60连接数据库 发布:2025-09-20 10:56:18 浏览:289
c语言ltoa 发布:2025-09-20 10:51:35 浏览:509
mysql的存储过程参数类型 发布:2025-09-20 10:41:58 浏览:819
linux系统怎么挂服务器 发布:2025-09-20 10:26:43 浏览:872