Zip文件解压
来源:互联网 发布:李斯璇 留学爆料 知乎 编辑:程序博客网 时间:2024/04/30 10:29
/*
* 功能: 文件解压
* 用法: java ExtractZipFile zipfile DestinationPath
* 注意: 不能建立子目录
*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ExtractZipFile {
public int scan(String filename) {
ZipEntry entry = null;
int filecount = 0;
try {
ZipInputStream zin = new ZipInputStream(new FileInputStream(
filename));
System.out.println("开始扫描 " + filename + ":");
System.out.println("-------------------------");
while ((entry = zin.getNextEntry()) != null) {
if (entry.isDirectory() || entry.getName().equals("..//")) {
continue;
}
System.out.println(entry.getName());
filecount++;
zin.closeEntry();
}
zin.close();
return filecount;
} catch (IOException e) {
System.out.println(e);
return -1;
}
}
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("*******************************************");
System.out.println("* 用法: java zip/jar 文件 目标路径 *");
System.out.println("* Usage: java zip/jarFile DestinationPath *");
System.out.println("*******************************************");
System.exit(-1);
}
// First Scan the Zip File
ScanZipFile scanzipfile = new ScanZipFile();
if (scanzipfile.scan(args[0]) < 0) {
System.out.println("Unzip Failed! Exiting now...");
System.exit(-1);
} else {
System.out.println("*******************************************");
System.out
.println("* Enter Y or y to extract the files, Any other key to exit! *");
System.out.println("*******************************************");
String inputString = "";
byte[] buffer = new byte[255];
try {
System.in.read(buffer, 0, 255);
inputString = new String(buffer);
} catch (IOException ex) {
System.out.println(ex);
}
if (inputString.indexOf("Y") != -1
|| inputString.indexOf("y") != -1) {
try {
ZipInputStream zin = new ZipInputStream(
new FileInputStream(args[0]));
ZipEntry entry;
System.out.println("Now Extracting the " + args[0] + ":");
String filename;
while ((entry = zin.getNextEntry()) != null) {
if (entry.isDirectory()
|| entry.getName().equals("..//")) {
continue;
}
System.out.println(entry.getName());
filename = args[1] + "//" + entry.getName();
byte[] buf = new byte[1];
BufferedInputStream bin = new BufferedInputStream(zin);
FileOutputStream tfos = new FileOutputStream(filename);
BufferedOutputStream bout = new BufferedOutputStream(
tfos);
while (bin.read(buf, 0, 1) != -1) {
bout.write(buf, 0, 1);
}
bout.close();
zin.closeEntry();
}
zin.close();
System.out
.println("*******************************************");
System.out
.println("* Extract Over ******");
System.out
.println("*******************************************");
} catch (IOException e) {
System.out.println(e);
}
} else {
System.out
.println("*******************************************");
System.out
.println("* Extract Quit ******");
System.out
.println("*******************************************");
System.exit(0);
}
}
}
/*
* 这个程序接收2个参数, 前一个参数表示要解压的 zip 文件, 后一个参数表示将文件解压到那个指定 目录下.它首先建立一个 ScanZipFile
* 对象, 然后执行这个对象上的 scan 方法, 将这个压缩文件 中的内容都显示到控制台上, 然后, 它试图从控制台得到一个指令,
* 用于指明是否对该压缩文件进行解压, 输入 y 或 Y, 将会开始执行解压操作,否则, 将退出整个应用.
*/
}
- nodejs zip 解压zip文件
- Zip文件解压
- Java解压zip文件
- zip文件上传下载 解压
- 解压*.zip.*的文件
- zip文件解压
- Android 解压zip文件
- zip文件目录解压
- 解压.zip文件命令
- android解压ZIP文件
- Android 解压zip文件
- 文件解压zip
- Android 解压zip文件
- zip文件解压
- android, 解压Zip文件
- zlib 解压zip文件
- Android 解压zip文件
- Android解压zip文件
- 编UDP聊天
- Java类体中的this和super的用法
- 案例 1-9: 解压缩 Zip 文件
- 我回来了
- 对目录进行压缩.
- Zip文件解压
- 在Java中有两个非常特殊的变量:this和super
- XP-SP2-您可能是软件盗版的受害者的解决方法
- ubuntu默认pdf阅读器evince显示中文乱码问题
- java里方法的参数传递
- 继承映射(一个表内)
- SDL入门教程(六):SDL读取其它格式的图片
- 新开blog
- SDL入门教程(七):SDL抠色(Color Keying)