[英]Saving a .txt file dynamically in Android sdcard0 when everytime applicaiion opens
[英]Saving a file in sdcard0 and sdcard1 android
我想給用戶一個選項,將視頻文件存儲在sdcard0(內部存儲器)或sdcard1中。 我怎樣才能做到這一點。 Environment.getExternalStorageDirectory()和Environment.getExternalPublicStorageDirectory()將文件保存在sdcard1中。 如何在sdcard0中保存文件?
試試這個代碼
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)");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.