【发布时间】:2015-11-19 13:32:12
【问题描述】:
我正在尝试读取一个 zip 文件,该文件位于我的插件项目中。这是文件层次结构:
my.super.project
- Referenced Libraries
- JRE System Library
- src
- binary
- META-INF
- resources
在资源目录中有一个压缩文件myarchive.zip,我想加载它。
这就是我尝试的方式:
byte[] buffer = new byte[1024];
try {
ZipInputStream zis = new ZipInputStream(new FileInputStream(
"resources/myarchive.zip"));
// get the zipped file list entry
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(OUTPUT_DIR
+ File.separator + fileName);
// create all non exists folders
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
ze = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
找不到文件(FileNotFoundException),表示相对路径有问题。
有什么问题以及如何读取 zip 文件?
【问题讨论】:
标签: java file eclipse-plugin zip inputstream