/存储/仿真/0/AndroidAPP/addon_data/plugin.audio.mp3streams/artist_icons/David Bowie.jpg:open failed:enoint(没有这样的文件或目录)
我想在android中提取zip文件。对于其他Zip文件,它工作正常,但我有一个Zip文件,无法解压缩到SD卡的任何路径。 它给了我这个错误/存储/仿真/0/AndroidAPP/addon_data/plugin.audio.mp3streams/artist_icons/David Bowie.jpg:open failed:enoint(没有这样的文件或目录),android,eclipse,extract,unzip,Android,Eclipse,Extract,Unzip,我想在android中提取zip文件。对于其他Zip文件,它工作正常,但我有一个Zip文件,无法解压缩到SD卡的任何路径。 它给了我这个错误 /storage/emulated/0/AndroidTVAPP/addon_data/plugin.audio.mp3streams/artist_icons/David Bowie.jpg: open failed: ENOENT (No such file or directory) 解压缩文件JAVA类 public class UnzipU
/storage/emulated/0/AndroidTVAPP/addon_data/plugin.audio.mp3streams/artist_icons/David Bowie.jpg: open failed: ENOENT (No such file or directory)
解压缩文件JAVA类
public class UnzipUtility
{
/**
* Size of the buffer to read/write data
*/
private static final int BUFFER_SIZE = 4096;
/**
* Extracts a zip file specified by the zipFilePath to a directory specified by
* destDirectory (will be created if does not exists)
* @param zipFilePath
* @param destDirectory
* @throws IOException
*/
public void unzip(String zipFilePath, String destDirectory) throws IOException
{
File destDir = new File(destDirectory);
if (!destDir.exists())
{
destDir.mkdir();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null)
{
String filePath = destDirectory + File.separator + entry.getName();
String filePath2 = File.separator + entry.getName();// filePath;
if (null != filePath2 && filePath2.length() > 0 )
{
int endIndex = filePath2.lastIndexOf("/");
if (endIndex != -1)
{
filePath2 = filePath2.substring(0, endIndex); // not forgot to put check if(endIndex != -1)
Log.e("File path=",""+filePath2);
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/AndroidTVAPP"+File.separator+filePath2);
if(dir.exists() == false){
dir.mkdirs();
}
}
}
if (!entry.isDirectory()) {
// if the entry is a file, extracts it
extractFile(zipIn, filePath);
} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
/**
* Extracts a zip entry (file entry)
* @param zipIn
* @param filePath
* @throws IOException
*/
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException
{
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
}您需要使用转义字符来指定文件名中有空格 试试这个
String path = "/storage/emulated/0/AndroidTVAPP/addon_data/plugin.audio.mp3streams/artist_icons/";
String fullPath= path + "David Bowie.jpg";
fullPath = fullPath.replace(" ", "\\ ");
或者您可以使用Uri.parse(path)
必须是文件名中的空格。你试过编码吗?@KNeerajLal可能有空间,因为zip文件大约有45MB,并且有很多文件,我是否应该在这里上传解压类,这样你就可以看到它,然后culd会帮助我。然后你需要。我已经修复了代码,同时我放了一些创建目录的行。上面的代码已经更新,并且工作正常。谢谢你告诉我在移动文件之前应该创建目录
public void unzip(String zipFilePath, String destDirectory) throws IOException {
...
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(Uri.parse(zipFilePath)));
...
}