Я пытаюсь распаковать файл из активов во внешнем хранилищеРаспакуйте почтовый файл из активов
public class Decompress {
public static void unzipFromAssets(Context context, String zipFile, String destination) {
try {
if (destination == null || destination.length() == 0)
destination = context.getFilesDir().getAbsolutePath();
InputStream stream = context.getAssets().open(zipFile);
unzip(stream, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void unzip(InputStream stream, String destination) {
dirChecker(destination, "");
byte[] buffer = new byte[BUFFER_SIZE];
try {
ZipInputStream zin = new ZipInputStream(stream);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v(TAG, "Unzipping " + ze.getName());
if (ze.isDirectory()) {
dirChecker(destination, ze.getName());
} else {
File f = new File(destination + ze.getName());
f.mkdirs();
File file = new File(f, destination + ze.getName());
FileOutputStream fout = new FileOutputStream(file);
int count;
while ((count = zin.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
Log.e(TAG, "unzip", e);
}
}
private static void dirChecker(String destination, String dir) {
File f = new File(destination + dir);
if (!f.isDirectory()) {
boolean success = f.mkdirs();
if (!success) {
Log.w(TAG, "Failed to create folder " + f.getName());
}
}
}
Everytime принять эту ошибку:
java.io.FileNotFoundException: filewebViewControllers/aboutAs/index.html/filewebViewControllers/aboutAs/index.html: open failed: ENOENT (No such file or directory)
Не удается найти файл назначения. Хорошо, как создать новый файл во внутренней памяти и сохранить данные там? –