gpt4 book ai didi

安卓解压打开失败: ENOENT (No such file or directory)

转载 作者:太空狗 更新时间:2023-10-29 15:08:17 24 4
gpt4 key购买 nike

我正在使用以下 code解压缩一组文件(也包含文件夹):

private boolean unpackZip(String path, String zipname)
{
InputStream is;
ZipInputStream zis;
try
{
String filename;
is = new FileInputStream(path + zipname);
zis = new ZipInputStream(new BufferedInputStream(is));
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;

while ((ze = zis.getNextEntry()) != null)
{
// zapis do souboru
filename = ze.getName();

// Need to create directories if not exists, or
// it will generate an Exception...
if (ze.isDirectory()) {
File fmd = new File(path + filename);
fmd.mkdirs();
continue;
}

FileOutputStream fout = new FileOutputStream(path + filename);

// cteni zipu a zapis
while ((count = zis.read(buffer)) != -1)
{
fout.write(buffer, 0, count);
}

fout.close();
zis.closeEntry();
}

zis.close();
}
catch(IOException e)
{
e.printStackTrace();
return false;
}

return true;
}

代码在 FileOutputStream fout = new FileOutputStream(path + filename) 上失败,错误为:

java.io.FileNotFoundException: /storage/emulated/0/BASEFOLDER/FOLDER1/FILE.png 

BASEFOLDER 已经存在,这是我尝试将文件夹解压缩到的位置。如果我手动(或以编程方式)创建 FOLDER1,代码运行良好并成功解压缩。我认为它正在崩溃,因为第一个文件 (ze) 名为 FOLDER1/FILE.png 并且 FOLDER1 尚未创建。我该如何解决这个问题?我知道其他人使用过此代码,我发现它不太可能随机对我不起作用...

最佳答案

你的 AndroidManifest.xml 文件中有这个吗?

添加写入外部存储权限

使用权限 android:name="android.permission.WRITE_EXTERNAL_STORAGE"

关于安卓解压打开失败: ENOENT (No such file or directory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19485117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com