我正在构建我想要从资产中解压缩数据库文件的应用程序。但我收到此错误java.io.FileNotFoundException: /file:/android_asset/kjv.zip: open failed: ENOENT (No such file or directory)
。
我正在使用此代码解压缩文件,
public void unzip(String _zipFile, String _targetLocation) {
//create target location folder if not exist
dirChecker(_targetLocation);
try {
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
//create dir if required while unzipping
if (ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(_targetLocation + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch (Exception e) {
Log.e("error", e + "");
}
}
private void dirChecker(String dir) {
File f = new File(dir);
if (!f.isDirectory()) {
f.mkdirs();
}
}
并使用此致电,
Uri path = Uri.parse("file:///android_asset/kjv.zip");
inputPath = path.toString();
ZipManager zipManager = new ZipManager();
zipManager.unzip(inputPath, outputPath);
我试过了,但每次都是错误的。无法理解问题所在。如果您有其他解决方案,请建议我。帮我。谢谢。