Android使用ZipFile提取zip文件时出现问题
try{
File f = new File("/data/cizip.zip");
if(f.exists()){
ZipFile zf = new ZipFile(f); //this always throws an error
/*some of my codes here*/
}
catch(IOException e){
AlertDialog.Builder abd = new AlertDialog.Builder(this);
abd.setMessage(e.getMessage());
abd.show();
}
行 ZipFile zf = new ZipFile(f);
总是抛出错误,我不知道为什么。并且错误消息是文件名(“/data/cizip.zip”),因此我无法知道错误的原因。有人可以告诉我导致此错误的原因吗?提前致谢。
try{
File f = new File("/data/cizip.zip");
if(f.exists()){
ZipFile zf = new ZipFile(f); //this always throws an error
/*some of my codes here*/
}
catch(IOException e){
AlertDialog.Builder abd = new AlertDialog.Builder(this);
abd.setMessage(e.getMessage());
abd.show();
}
the line ZipFile zf = new ZipFile(f);
always throws an error and I don't know why. And the error message is the file name ("/data/cizip.zip"), therefore I can't know the cause of the error. Can someone please tell me what causes this error? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是一个猜测,但也许该文件正在使用(锁定)?我没有看到你的代码有任何明显的错误......
This is just a guess, but maybe the file is in use (locked)? I don't see anything obviously wrong with your code...
您的应用程序没有直接在 /data/ 目录中的读/写权限。您应该使用正确的子文件夹“/data/data/your.program.package/”或仅使用“/sdcard/”
Your app doesn't have read/write permissions directly in the /data/ directory. You should use either the correct subfolder "/data/data/your.program.package/" or just the "/sdcard/"