I want to save a text file to the SD card I inserted into my HTC One M8 running lollipop. However when I run this code it saves to internal storage instead.
String FILENAME = "mysavefile.txt";
File file = new File(Environment.getExternalStorageDirectory(), FILENAME);
if (isExternalStorageWritable()) {
errorSD.setVisibility(View.INVISIBLE);
try {
FileOutputStream fos = new FileOutputStream(file, false);
fos.write(allInformation.getBytes(), 0, 81);
fos.close();
successfulSubmissionToast();
} catch (FileNotFoundException e) {
e.printStackTrace();
errorSD.setVisibility(View.VISIBLE);
} catch (IOException e) {
e.printStackTrace();
}
It should be saving to
/storage/ext_sd
but instead it is saving to
/storage/emulated/0
Then I tried manually entering in the location of my SD card to see if that would work but it ended up throwing the FileNotFoundException
File file = new File("/storage/ext_sd", FILENAME);
Edit: I believe the issue is that there are multiple external storages. One being permanent and one temporary. The question is how do you access the second one.