我正在尝试解压缩从服务器下载的文件。我正在使用getFilesDir()
,以便用户无法访问这些文件。但是在创建.eot文件时会崩溃
这是代码:
if(fin == null) {
fin = new FileInputStream(_zipFile);
}
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v(TAG, "Unzipping " + ze.getName());
Log.v(TAG,ze.getName()+"="+ze.isDirectory());
if(ze.isDirectory()) {
_dirChecker(context.getFilesDir().getPath() +"/" + ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(new File(context.getFilesDir().getPath(),ze.getName()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
// reading and writing
while((count = zin.read(buffer)) != -1)
{
baos.write(buffer, 0, count);
byte[] bytes = baos.toByteArray();
fout.write(bytes);
baos.reset();
}
fout.close();
zin.closeEntry();
}
这是日志条目
07-12 16:52:38.480 22922-22922/com.example.karthik.storing_data_downloaded_from_online E/UNZIPUTIL: Unzip Error
java.io.FileNotFoundException: /data/user/0/com.example.karthik.storing_data_downloaded_from_online/files/assets/fonts/fontawesome-webfont.eot (Not a directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
at com.example.karthik.storing_data_downloaded_from_online.Decompress.unzip(Decompress.java:60)
at com.example.karthik.storing_data_downloaded_from_online.MainActivity$1.downloadDone(MainActivity.java:54)
at com.example.karthik.storing_data_downloaded_from_online.DownloadFileAsync.onPostExecute(DownloadFileAsync.java:91)
at com.example.karthik.storing_data_downloaded_from_online.DownloadFileAsync.onPostExecute(DownloadFileAsync.java:21)
at android.os.AsyncTask.finish(AsyncTask.java:660)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
错误在这一行
FileOutputStream fout = new FileOutputStream(new File(context.getFilesDir().getPath(),ze.getName()));