import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
public class UnZIPcontrol {
/**
* 创建目录
*
* @param path
* 目录绝对路径名
*/
static void createDir(String path) {
File dir = new File(path);
if (dir.exists() == false)
dir.mkdir();
}
/**
* 取得文件名,不包含后缀名
*
* @param name
* 完整文件名
* @return 文件名(不包含后缀名)
*/
static String getSuffixName(String name) {
return name.substring(0, name.lastIndexOf("."));
}
public static void main(String[] args) throws Exception {
// unzip("E:/apache-tomcat-6.0.29.zip", "E:");
unzip("E:/test005.zip", "E:");
System.out.println("over....................");
}
/**
* 解压zip文件
*
* @param zipFilePath
* zip文件绝对路径
* @param unzipDirectory
* 解压到的确
* @throws Exception
*/
public static String unzip(String zipFilePath, String unzipDirectory)
throws Exception {
// 创建文件对象
File file = new File(zipFilePath);
// 创建zip文件对象
ZipFile zipFile = new ZipFile(file);
// 创建本zip文件解压目录
File unzipFile = new File(unzipDirectory + "/"
+ getSuffixName(file.getName()));
if (unzipFile.exists())
unzipFile.delete();
unzipFile.mkdir();
// 得到zip文件条目枚举对象
Enumeration zipEnum = zipFile.getEntries();
// 定义输入输出流对象
InputStream input = null;
OutputStream output = null;
// 定义对象
ZipEntry entry = null;
// 循环读取条目
while (zipEnum.hasMoreElements()) {
// 得到当前条目
entry = (ZipEntry) zipEnum.nextElement();
String entryName = new String(entry.getName());
// 用/分隔条目名称
String names[] = entryName.split("\\/");
int length = names.length;
String path = unzipFile.getAbsolutePath();
for (int v = 0; v < length; v++) {
if (v < length - 1) { // 最后一个目录之前的目录
path += "/" + names[v] + "/";
createDir(path);
} else { // 最后一个
if (entryName.endsWith("/")) // 为目录,则创建文件夹
createDir(unzipFile.getAbsolutePath() + "/" + entryName);
else { // 为文件,则输出到文件
input = zipFile.getInputStream(entry);
output = new FileOutputStream(new File(unzipFile
.getAbsolutePath()
+ "/" + entryName));
byte[] buffer = new byte[1024 * 8];
int readLen = 0;
while ((readLen = input.read(buffer, 0, 1024 *
) != -1)
output.write(buffer, 0, readLen);
// 关闭流
input.close();
output.flush();
output.close();
}
}
}
}
return unzipFile.getName();
}
}
分享到:
相关推荐
在Windows操作系统中,"zip"和"unzip"是指对文件进行压缩和解压缩的操作。Zip是一种常用的文件格式,用于将多个文件或文件夹打包成一个单一的档案,以节省存储空间和便于传输。在Windows中,有多种方法可以处理zip...
var sourceFiles:Array = [File.applicationDirectory.resolvePath("file1.txt"), File.applicationDirectory.resolvePath("folder1")]; var zipFile:File = File.applicationDirectory.resolvePath("compressed_...
例如,`unzip file.zip -d destination_folder`将把zip文件中的内容解压到destination_folder目录下。 3. **tar**:tar最初是用于在Unix系统中打包文件,但它并不直接进行压缩。`tar`命令常与其他压缩工具结合使用...
通常我们解压缩一个Zip,最简单的方法就是直接在这个Zip文件上点击鼠标右键,然后选择 Extract To folder 将这个Zip文件解压到目录中。 批量解压缩(Batch UnZip)也可以结合到Windows右键菜单—— 先选中要解压...
ML语言基本的函数模块,递归生成,folder函数实现,map函数,zip,unzip,对列表进行操作
MATLAB的标准函数`unzip`能够帮助用户方便地完成这一操作。然而,标准的`unzip`函数会将整个压缩文件解压到指定的目录,而不会提供选择性解压的选项。针对这种情况,"unzip file\s"的功能扩展了MATLAB的解压缩能力,...
Then, unzip GIXSGUI folder. Start Matlab. On the Home tab, click "Set Path" > "Add with Subfolders..." and select the folder that contains the GIXSGUI distribution. Click "Save" and "Close".
1.Use WinRAR or 7-ZIP to unzip HPUSBFW.EXE to folder "HPUSBFW" There will be 8 files inside this folder. 2.Execute HPUSBFW.EXE 3.Select the USB device you want to format. 4.Check "Create a DOS ...
the top-level folder to any location you prefer on your hard drive. The projects all use relative paths and do not rely on the top-level directory being located at the root of the drive. The Macintosh...
You simply download the package and unzip it to a folder. If that did not work out, you may have to install needed runtimes. Download and install Microsoft ActiveX End-User Runtimes (March 2008 or ...
the top-level folder to any location you prefer on your hard drive. The projects all use relative paths and do not rely on the top-level directory being located at the root of the drive. The Macintosh...
Download HWDB dataset and unzip to data folder run python process_gnt.py to generate img from gnt fiel. Due to the huge dataset (897758+223991 images), it may take a lot of time. I suggest to put the ...
例如`myUnzip.Extract("target_path_in_zip\\source_file.txt", "destination_folder\\source_file.txt");`。 4. **获取ZIP信息:** 可以使用`GetFileCount`、`GetFileInfo`等函数获取ZIP文件的信息,例如文件数量...
linux仿win10主题,Win10 Icons Pack - GNOME Icon Theme Description: I found this icon pack by ...4) copy the folder pack from ( home / username / ..(folder pack).. ) and paste it in (usr / share / icons)
1. Extract the Zen Cart ZIP file (and tell the unzip utility to *retain* folder structures) 2. Upload the Zen Cart files and folders to your server using your FTP program 3. You must make some folders...
例如,`mv file1 file2` 将 `file1` 重命名为 `file2`,`mv folder1 folder2/newfolder` 移动 `folder1` 到 `folder2` 目录下并命名为 `newfolder`。 4. `du` 和 `df`: - `du` 用于查看目录占用的磁盘空间。例如...
标题中的“问题完美解决 keil官网方法encounter an inmproper argument”指的是在使用MDK5(Microcontroller Development Kit)时遇到的一个特定错误:“encounter an improper argument”。这个错误通常出现在用户...
1. Extract the Zen Cart ZIP file (and tell the unzip utility to *retain* folder structures) 2. Upload the Zen Cart files and folders to your server using your FTP program 3. You must make some folders...
0)Unzip the zip file -- Remember to extract paths! 1)Open 'Linker.vbp' (in the 'linker' folder) and compile it. 2)Copy the 'MakeDLL.exe' file (in the 'compiled' folder) to your Visual Basic ...
s toolbox folder or whatever folder you want Be sure to add MATLAB RLINK to your Matlab path 4 Use template and function In the content of matlab2r m there"s a line: matlab2r "y x^2" ...