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?
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");
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)");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.