在Java中如何解压缩扩展名为.Z的压缩文件 扩展名为.Z的压缩文件为LINUX系统下的压缩文件类型,它有独立的算法.我想求助各位大虾,教我如何在Java中解压缩扩展名为.Z的压缩文件,如有操作.Z文件类型的包(比如:java.util.zip.*;是操作ZIP类型的压缩文件的包)更好. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你一个我自己刚写的方法:一次性解压 * <p>缺陷:不能解压zip文件中存在中文的文件</p> * @param astrZipPath String --> 解压缩后文件存放的路径 * @param astrZipFile String --> 需要解压缩的zip文件 public void UnZipI(String astrZipPath, String astrZipFile) { ZipInputStream ZipOut = null; // 利用Zip输入流来进行读取文件,进行解压 ZipEntry zEntry = null; // Zip文件中的压缩文件实体 try { // 读文件 ZipOut = new ZipInputStream(new FileInputStream(astrZipFile)); while ((zEntry = ZipOut.getNextEntry()) != null) { // 检测文件是否存在不存在则创建,进入下一循环 if (zEntry.isDirectory()) { File dir = new File(astrZipPath + zEntry.getName().toString()); if (!dir.exists()) { dir.mkdir(); } continue; } System.out.println("Extracting... " + zEntry); // 创建与zip文件中相同的文件 DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(astrZipPath + Utf8toGbk(zEntry.getName())))); String strSize = String.valueOf(zEntry.getSize()); int iSize = 1024; iSize = Integer.parseInt(strSize); byte[] buf = new byte[iSize]; // 将zip文件中的数据写出 while (ZipOut.read(buf, 0, buf.length) != -1) { out.write(buf, 0, buf.length); } ZipOut.closeEntry(); out.close(); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { ZipOut.close(); } catch (IOException ex) { ex.printStackTrace(); } } }该解压方式是利用ZipInputStream进行解压,还有别的方式可以解压 yoyozo!谢谢您的帮助.您的程序我已测试过,现在有两个问题.1.Utf8toGbk()这个方法,是系统的还是自己创建的?2.// 读文件 ZipOut = new ZipInputStream(new FileInputStream(astrZipFile)); 读不到.Z类型的文件.ZipOut.getNextEntry()=NULL; 不好意思:Utf8toGbk()方法如下: public static String Utf8toGbk(String str) { if (str == null) { str = ""; } String strTmp = null; try { strTmp = new String(str.getBytes("ISO-8859-1"), "GBK"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); strTmp = ""; } //return new String(str.getBytes("ISO-8859-1"), "GBK"); return strTmp; }2/.Z类型的文件是压缩文件吗,类ZipInputStream是专门提供给压缩文件读取的. 扩展名为.Z的压缩文件为LINUX系统下的压缩文件类型,它是由compress压缩的文件.而ZipInputStream好象读不出来这种压缩文件. 数组的移除问题? struts中的select标签没有onpropertychange 属性? format 如何在地图中取区域。。。 将一个字符串唯一映射到一个整形,有什么方法? 请给个思路:来着有分 求jBuild8 序列号 jbuilder4有没有bug? JAVA 中的接口到底是什么东东 ? 请各位指教 synchronized同步代码块失效的问题 请问SimpleDateFormat问题,对日期format后生成字符串,在对此字符串format就出错,不知道为什么? 现在主流的JAVA开发环境是什么工具呀?
一次性解压
* <p>缺陷:不能解压zip文件中存在中文的文件</p>
* @param astrZipPath String --> 解压缩后文件存放的路径
* @param astrZipFile String --> 需要解压缩的zip文件 public void UnZipI(String astrZipPath, String astrZipFile) {
ZipInputStream ZipOut = null; // 利用Zip输入流来进行读取文件,进行解压
ZipEntry zEntry = null; // Zip文件中的压缩文件实体
try {
// 读文件
ZipOut = new ZipInputStream(new FileInputStream(astrZipFile));
while ((zEntry = ZipOut.getNextEntry()) != null) {
// 检测文件是否存在不存在则创建,进入下一循环
if (zEntry.isDirectory()) {
File dir = new File(astrZipPath + zEntry.getName().toString());
if (!dir.exists()) {
dir.mkdir();
}
continue;
}
System.out.println("Extracting... " + zEntry);
// 创建与zip文件中相同的文件
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(astrZipPath +
Utf8toGbk(zEntry.getName()))));
String strSize = String.valueOf(zEntry.getSize());
int iSize = 1024;
iSize = Integer.parseInt(strSize);
byte[] buf = new byte[iSize];
// 将zip文件中的数据写出
while (ZipOut.read(buf, 0, buf.length) != -1) {
out.write(buf, 0, buf.length);
}
ZipOut.closeEntry();
out.close();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
ZipOut.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}该解压方式是利用ZipInputStream进行解压,还有别的方式可以解压
1.Utf8toGbk()这个方法,是系统的还是自己创建的?
2.// 读文件
ZipOut = new ZipInputStream(new FileInputStream(astrZipFile));
读不到.Z类型的文件.ZipOut.getNextEntry()=NULL;
public static String Utf8toGbk(String str) { if (str == null) {
str = "";
}
String strTmp = null;
try {
strTmp = new String(str.getBytes("ISO-8859-1"), "GBK");
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
strTmp = "";
}
//return new String(str.getBytes("ISO-8859-1"), "GBK");
return strTmp;
}
2/.Z类型的文件是压缩文件吗,类ZipInputStream是专门提供给压缩文件读取的.