我压缩了一个名为dir2的目录,其中包含一些文本文件。我想在外部存储中创建一个名为dir的目录,该目录包含dir2。
给定一个压缩的dir2,我试图提取所以它看起来像: external_storage_path /目录/ DIR2 / TextFile.txt的
createFile(zis, "dir2/textfile.txt");
private void createFile(ZipInputStream zipIn, String filename) {
if(android.os.Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
boolean created = false;
File newFile = new File(Environment.getExternalStorageDirectory(),
"dir/dir2/textfile.txt");
if(!newFile.exists()) {
// create the file and any parent dirs if needed
created = newFile.mkdirs();
}
if(created) {
BufferedOutputStream bos = null;
try {
FileOutputStream fos = new FileOutputStream(newFile.getAbsolutePath());
bos = new BufferedOutputStream(fos);
} catch (FileNotFoundException fnf) {
fnf.printStackTrace();
}
尝试创建BufferedOutputStream时抛出异常:
java.io.FileNotFoundException:
/storage/emulated/0/dir/dir2/textfile.txt: open failed: EISDIR (Is a
directory)
文本文件不是目录。