扩展名为.Z的压缩文件为LINUX系统下的压缩文件类型,它有独立的算法.我想求助各位大虾,教我如何在Java中解压缩扩展名为.Z的压缩文件,如有操作.Z文件类型的包(比如:java.util.zip.*;是操作ZIP类型的压缩文件的包)更好.
解决方案 »
- 单例模式跟工厂模式的结合。。
- 关于InvocationHandler,请路过的同仁帮忙解释一下!
- 求书:《j2se进阶》《java编程思想 第二版 侯捷译》
- 一个小的FileWriter问题;
- 菜鸟急问一个GUI问题,请高手帮忙解决
- 一个密码验证问题
- 我要做一个用java语言实现的将jpeg图像转成BMP图像的程序,请高手帮帮忙!!!!
- 正则表达式分割字符串时候中文出现乱码,怎么解决
- 关于mysql驱动器
- import自定义类 的问题
- 请问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是专门提供给压缩文件读取的.