你要是解压zip文件的话还好说,java中有对zip文件的支持
rar,你就要看看有没有相关控件了
或者你找一些rar的资料,自己搞一个
rar,你就要看看有没有相关控件了
或者你找一些rar的资料,自己搞一个
解决方案 »
- 用Java编写一个数组里的最大数值
- 写汇率转换软件时遇到的关于Text的使用问题
- hibernate查询问题
- 请大家帮忙看下我这段代码有什么问题,帮忙指正下.谢谢啦
- java中有没有getscreen()和player()函数
- 怎样使TLabelField中显示的字符为***
- ★一个非常非常非常简单的送分问题 ★ 一个在Applet 中两个label中,输入输出字符串的入门小例子,为什么只能显示一个label呢?我的代码
- 如何将一个象素点设置成某一种颜色(即绘制一个象素点).
- 看看java的魅力
- 请问:java最适合哪方面的软件开发?服务器端?应用程序?
- StringBuffer
- 菜鸟问题,谢谢
* <p>Title: 解压文件处理 </p>
* <p>Description: 实现与解压文件的相关的处理 </p>
* <p>Copyright: Copyright (c) 2003-2010</p>
* @version 1.0 03/08/12
*/import java.io.*;
import java.util.*;
import java.util.zip.*;
import sun.io.*;public class Zip {
public String errMsg = ""; public Zip() {
} /**
* 解压文件
* @param filePath 文件路径
* @param fileName 文件名称
* @return 错误信息字符串
*/
public String execute(String filePath, String fileName) {
File infile = new File(filePath + fileName);
try {
//检查是否是一个zip文件
ZipFile zip = new ZipFile(infile);
zip.close();
//建立与目标文件的输入连接
ZipInputStream in = new ZipInputStream(new FileInputStream(infile));
ZipEntry file = in.getNextEntry();
int i = infile.getAbsolutePath().lastIndexOf(".");
String dirname = new String();
if (i != -1) {
dirname = infile.getAbsolutePath().substring(0, i);
} else {
dirname = infile.getAbsolutePath();
}
///JOptionPane.showMessageDialog(null, "1. " + dirname, "显示", JOptionPane.CLOSED_OPTION);
File newdir = new File(dirname);
newdir.mkdir();//创建第一级目录 byte[] c = new byte[1024];
int len;
int slen; while (file != null) {
i = file.getName().replace('/', '\\').lastIndexOf('\\');
if (i != -1) {
File dirs = new File(dirname + File.separator + file.getName().replace('/', '\\'));
dirs.mkdir();
dirs = null;
///JOptionPane.showMessageDialog(null, "2. " + String.valueOf(i) + dirname + File.separator + file.getName().replace('/', '\\').toString(), "显示", JOptionPane.CLOSED_OPTION);
//System.exit(0);
} if (file.isDirectory()) {
File dirs = new File(dirname + File.separator + file.getName().replace('/', '\\'));
dirs.mkdir();
dirs = null;
///JOptionPane.showMessageDialog(null, "3. " + dirname + File.separator + file.getName().replace('/', '\\').toString(), "显示", JOptionPane.CLOSED_OPTION);
} else {
FileOutputStream out = new FileOutputStream(dirname + File.separator + file.getName().replace('/', '\\'));
while ((slen = in.read(c, 0, c.length)) != -1) {
out.write(c, 0, slen);
}
out.close();
} file = in.getNextEntry(); }
errMsg = infile.getName() + "解压成功!";
in.close();
return errMsg; } catch (ZipException zipEx) {
errMsg = infile.getName() + "不是一个zip文件!";
return errMsg;
} catch (IOException ioEx) {
errMsg = "读取" + infile.getName() + "文件时出错!";
return errMsg;
} catch (Exception Ex) {
errMsg = infile.getName() + "文件不存在!";
return errMsg;
}
}
}http://xieweibbs.topcities.com