I want to give an option to the user to store a video file in sdcard0(internal memory) or sdcard1. How can I do that. Environment.getExternalStorageDirectory() and Environment.getExternalPublicStorageDirectory() will save the file in sdcard1. How can I save a file in sdcard0?
Asked
Active
Viewed 1,527 times
1
-
Possible duplicate of http://stackoverflow.com/questions/23466753/storing-a-file-on-internal-and-external-sdcard – Veener Apr 04 '16 at 02:18
-
That solution didnt help me. He is hardcoding the path. I dont want to hardcode the path as the path can vary in different devices – S.Khan Apr 04 '16 at 02:25
2 Answers
0
Try this code
String sdcard_path = Environment.getExternalStorageDirectory().getPath();
Log.d("Path ------ ", " " + sdcard_path);
// create a File object for the parent directory
File PapersDiractory = new File(sdcard_path + "/Exam Papers/");
// have the object build the directory structure, if needed.
PapersDiractory.mkdirs();
// create a File object for the output file
File outputFile = new File(PapersDiractory, "five-point-someone-chetan-bhagat_ebook.pdf");

Arpit Patel
- 7,212
- 5
- 56
- 67
0
ContextWrapper contextWrapper = new ContextWrapper(
getApplicationContext());
File directory = contextWrapper.getDir(filepath,Context.MODE_PRIVATE);
myInternalFile = new File(directory, filename);
try {
FileOutputStream fos = new FileOutputStream(myInternalFile); // save
fos.write(myInputText.getText().toString().getBytes());
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
myInputText.setText("");
responseText.setText("Saved to Internal Storage.(StorageFile.txt)");

bhumika rijiya
- 440
- 1
- 5
- 42