如何用java或者批处理命令 实现解压一个rar或zip文件 到选择的目录下 并生成桌面快捷方式
展开全部
/**
* 解压课件包中的某个课件
* @param zipFilePath 课件包路径
* @param outDirPath 输出目录路径
* @return 解压出来文件的绝对路径,失败返回null
* @throws IOException
*/
public String decompressAllFileToDir(String zipFilePath, String outDirPath) throws IOException {
ZipFile zip = new ZipFile(zipFilePath, "GBK");
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> entries = zip.getEntries();
if (entries == null) {
return null;
}
java.io.File file = new java.io.File(outDirPath);
String path = file.getAbsolutePath();
file.mkdirs();
if (file.isFile()) {
return null;
}
while(entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
String nameInZip = entry.getName().substring(entry.getName().lastIndexOf("/")+1);
InputStream is = zip.getInputStream(entry);
java.io.File tempFile = new java.io.File(nameInZip);
FileOutputStream fos = new FileOutputStream(new StringBuilder(path).append("/").append(tempFile.getName()).toString());
byte[] bytes = new byte[MAX_BUFFER];
int size = 0;
while ((size = is.read(bytes)) != -1) {
fos.write(bytes, 0, size);
}
}
return zipFilePath;
}
* 解压课件包中的某个课件
* @param zipFilePath 课件包路径
* @param outDirPath 输出目录路径
* @return 解压出来文件的绝对路径,失败返回null
* @throws IOException
*/
public String decompressAllFileToDir(String zipFilePath, String outDirPath) throws IOException {
ZipFile zip = new ZipFile(zipFilePath, "GBK");
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> entries = zip.getEntries();
if (entries == null) {
return null;
}
java.io.File file = new java.io.File(outDirPath);
String path = file.getAbsolutePath();
file.mkdirs();
if (file.isFile()) {
return null;
}
while(entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
String nameInZip = entry.getName().substring(entry.getName().lastIndexOf("/")+1);
InputStream is = zip.getInputStream(entry);
java.io.File tempFile = new java.io.File(nameInZip);
FileOutputStream fos = new FileOutputStream(new StringBuilder(path).append("/").append(tempFile.getName()).toString());
byte[] bytes = new byte[MAX_BUFFER];
int size = 0;
while ((size = is.read(bytes)) != -1) {
fos.write(bytes, 0, size);
}
}
return zipFilePath;
}
追问
这个 东西没有啊 MAX_BUFFER
追答
private static final int MAX_BUFFER = 0x200000;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询