I have this code that’s supposed to unzipp a file.
public class dec extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this, "hello, starting to unZipp!", 15500).show();
String location = Environment.getExternalStorageDirectory() + "/unzipped/";
/////////////////////////////////////////////////////////////////////
try {
ZipInputStream zin = new ZipInputStream(getAssets().open("totalkeys.zip"));
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "My UNZIPPING: " + ze.getName());
if(ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(location + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.v("Decompress", "My ERROR: "+e.toString());
/// throws My ERROR: java.io.FileNotFoundException: /mnt/sdcard/unzipped/Eng_blue/altlayout.txt (No such file or directory)
/// and dies.
}
}
////////////////////////////////////////////////////
private void dirChecker(String dir) {
String location = Environment.getExternalStorageDirectory() + "/unzipped/";
File f = new File(location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
////////////////////////////////////////////////////
finish();
}
}
Yet it only throws “ava.io.FileNotFoundException: /mnt/sdcard/unzipped/Eng_blue/altlayout.txt” which is the name of the first file and dies.
I thought that dirChecker() method would create this folders on the flow… any ideas how to fix that?
Thanks!
Make sure you added the
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />permission to your AndroidManifest.xml file