I am trying to write a simple test method to copy a file from the Asset folder to the sd card. When I try to open a file on the sd card it crashes.
code
try {
// POpne file from asset
AssetManager assetManager = getAssets();
InputStream inputStream;
inputStream = assetManager.open("test");
// open output folder
File externalStorage = Environment.getExternalStorageDirectory();
// CRASHES HERE
out = new FileOutputStream( externalStorage.getAbsolutePath() );
int c;
while ((c = inputStream.read()) != -1) {
out.write(c);
}
} catch( Exception e) {
}
}
It looks like you forgot to mention File Access permission in AndroidManifest.xml, just write following permission in your AndroidManifest.xml