Right now I am trying to make an application that basically creates 100 files on SD card using a for loop.
I have looked into a lot of related questions and posts and I can't happen to solve it myself. I am using Android Studio's built-in emulator as my testing device since I prefer not to run it on my actual phone...
Anyway I created a button which if you click, it produces 100 files on external storage (well that's my intention though -_-).
So far I have this,
for (int i=1; i <= 100; i++) {
sdPath = Environment.getExternalStorageDirectory() + "/Android/";
File file = new Files(sdPath + "hacked" + i);
try{
FileOutputStream fos = new FileOutputStream(file);
fos.close();
}catch (Exception e){Log.i("Failed to save", e.getMessage());
}
This is the main implementation of file creation so far. I have edited my Manifest to include permission to write external storage but every time when I run the application I get /sotrage/0B01-3415/Android/hacked 1-100: open failed: EACCESS (Permission denied)
message.
Does anyone happen to know what is causing the trouble???
Also what I don't understand is, when we use Environment.getExternalStorageDirectory
, what does it really mean? In my actual phone, directories are like /sdcard/Android/data
.... like this form.