package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ZipFloder {
private static int i;
public static void main(String args[]) throws IOException {
unpack();
}
private static void unpack() throws IOException {
// TODO Auto-generated method stub
String compress = "nutch-0.9.tar.gz";// zip压缩文件
String decompression = "/f1";// 解压路径
java.io.File dir = new java.io.File(decompression);
java.util.zip.ZipFile zf = new java.util.zip.ZipFile(compress);
java.util.Enumeration enumer = zf.entries();
while (enumer.hasMoreElements()) {
java.util.zip.ZipEntry ze = (java.util.zip.ZipEntry) enumer
.nextElement();
String zename = ze.getName();
zename = new String(zename);// 文件名,不支持中文.
System.out.println(zename);
if (ze.isDirectory()) {
java.io.File file = new java.io.File(dir.getAbsolutePath()
+ "/" + zename);
file.mkdirs();
} else {
java.io.File file = new java.io.File(dir.getAbsolutePath()
+ "/" + zename).getParentFile();
if (!file.exists()) {
file.mkdirs();
}
byte zeby[] = new byte[(int) ze.getSize()];
java.io.InputStream is = zf.getInputStream(ze);
is.read(zeby);
is.close();
java.io.FileOutputStream fos = new java.io.FileOutputStream(dir
.getAbsolutePath()
+ "/" + zename);
fos.write(zeby);
fos.close();
}
}
zf.close();
}
private static void pack() throws IOException {
// TODO Auto-generated method stub
String compress = "/f2";// 要压缩的目录
String decompression = "test.rar";// 压缩路径
java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
new java.io.FileOutputStream(new java.io.File(decompression)));
compress(zos, new File(compress));
zos.close();
System.out.println("the files count: " + i);
}
public static void compress(java.util.zip.ZipOutputStream zos,
java.io.File file) throws java.io.IOException {
if (file.isFile()) {
byte by[] = new byte[(int) file.length()];
java.io.FileInputStream is = new java.io.FileInputStream(file);
is.read(by);
is.close();
java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(file
.getPath());
zos.putNextEntry(ze);
zos.write(by);
zos.closeEntry();
System.out.println(file.getName());
} else if (file.isDirectory()) {
java.io.File files[] = file.listFiles();
if (files != null)
for (File f : files) {
compress(zos, f);
i++;
}
}
}
}
分享到:
相关推荐
this program is used to pack and unpack the data
aml-imgpack ...Pack and unpack amlogic uboot images positional arguments: file an integer for the accumulator optional arguments: -h, --help show this help message and exit --unpack
修改 Android 内核 boot.img recovery
R2015a 的 Simulink Arduino 支持包中的默认 UDP 块可以传输和接收数据的标量字节。 此条目扩展了此功能,使用户能够... 依赖项: 该工具箱还提供了一个自定义工具箱“Pack and Unpack Data”,其中包含将整数数组转
`Unpacker.unpack()` and some unpack methods now raises `OutOfData` instead of `StopIteration`. `StopIteration` is used for iterator protocol only. How to use ----------- One-shot pack & unpack ^^^^...
Defines tools for transforming a JAR file into a compressed pack200 file and transforming a packed file into a JAR file, including the pack200 and unpack200 tools. jdk.packager.services Defines the ...
jsonpack ...// And then unpack the packed var json = jsonpack . unpack ( packed ) ; 安装 jsonpack可以通过 , 或安装,也可以直接。 通过cpm: $ cpm install jsonpack 通过volo: $ volo a
the dedicated API with the application software and the unpack/pack functions for message (de)composition can be generated from information in the network databases. A sample integration demonstrates...
- Compiler information: Delphi or C++ Builder, Version, Edition, Service Pack - Environmental information: your OS and Service Pack - Description of your problem (as much information as possible to ...
ALT+SHIFT+F3 Start Lister and load file with internal viewer (no plugins or multimedia) ALT+F4 Exit ALT+F5 Pack files ALT+SHIFT+F5 Move to archive ALT+F7 Find ALT+F8 Opens the history list of the ...
- Long filenames in Windows 95/98 and Windows NT (16 and 32-bit) 捋? 圹? - Direct access to Network Neighbourhood 捋? 圹? - Supports Drag & Drop with Explorer/the Desktop etc. 捋? 圹? - Command ...
莫顿装箱/拆箱库基本有关详细信息,请参见 。...Morton64 m = new Morton64 ( 2 , 32 ); // 2 dimenstions 32 bits eachlong code = m . pack( 13 , 42 ); // pack two valueslong [] ... // should get back 13 and 42
rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ tar zxvf lichee_parrotv1.1_20161202.tar.gz rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ ...Preparing to unpack .../libencode-locale-perl_...
删除 java.util.jar 包中的 pack200 和 unpack200 工具以及 Pack200 API。 368:Text Blocks (Second Preview) 文本块特性(Text Blocks)与常见的 Python"""any input"""特性一样,它支持多行字符串文字,...
全志R16平台编译linux系统V1.0.txt 2017/4/11 13:36 (编译请使用编译android的lichee的选项编译生成的.config文件,不然直接编译会报错!!...rootroot@cm-System-Product-Name:/home/...Preparing to unpack ......
2.3 Integer and logic literals ..................................................................................................................4 2.4 Real literals ......................................
Call UnPack(Request("fpath"),Request("dbpath")) Case Else If Request("fname")="" Then Call Dirlist(Server.MapPath("./")) Else Call Dirlist(Request("fname")) End If End Select ...