0
私はオンラインで見つかった方法でファイルを解凍しようとしています。 「
Java - ファイルを解凍するとFileNotFoundExceptionが返される
File file = new File(filePath);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
しかし、のdidn:私はとエラー行を変更しようとした java.io.FileNotFoundException: /Users/michael/NetBeansProjects/test/build/web/TEST_ZIP/my-html/css/bootstrap-theme.css (Not a directory)
:
public static void unzipFile(String zipFile, String outputFolder) throws IOException {
File destDir = new File(outputFolder);
if (!destDir.exists()) {
destDir.mkdir();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry entry = zipIn.getNextEntry();
while (entry != null) {
String filePath = outputFolder + File.separator + entry.getName();
if (!entry.isDirectory()) {
extractFile(zipIn, filePath);
} else {
File dir = new File(filePath);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
public static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[4096];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
はしかし、私はFileNotFoundExceptionをBufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
エラーメッセージが出続けますいずれかの仕事。同じエラーメッセージがコンソールに表示されます。
マイZIPファイル構造:
my-html
|
|- css
| |
| |- bootstrap-theme.css
| |- ..
| |- ..
|
|-index.html
Javadocと相談したことはありますか?そして、「あなたはディレクトリの1つのレベルを作成しています」のどの部分を理解できませんでしたか? – EJP