![](/img/trans.png)
[英]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.