如何找到外部存储目录 [英] How to find external storage directory
本文介绍了如何找到外部存储目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static final String FILE_LOG = "log.txt";
private void SaveLogToExternalStorage()
{
String s = tv_log.getText().toString();
File file;
FileOutputStream fos = null;
try
{
file = new File(getExternalFilesDir(null), FILE_LOG);
fos = new FileOutputStream(file);
}
catch(FileNotFoundException e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
try
{
fos.write(s.getBytes());
fos.close();
}
catch(IOException e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
String savedFile = Environment.getExternalStorageDirectory() + "/" + FILE_LOG;
Toast.makeText(this, "Log is saved to " + savedFile, Toast.LENGTH_SHORT).show();
}
这个函数打印日志将被保存到MNT / SD卡/ log.txt的
其实,文件保存到 MNT / SD卡/ Android的/数据/ package.name/files/log.txt
如何编程找到这个目录显示正确的信息?
This function prints Log is saved to mnt/sdcard/log.txt
Actually the file is saved to mnt/sdcard/Android/data/package.name/files/log.txt
How can I find this directory programmatically to show correct message?
推荐答案
通过解决 file.getAbsolutePath()
这篇关于如何找到外部存储目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文