如何解决无法使用Android Studio查找存储的文件
我正在尝试将文件保存在我的Android应用中,以便可以使用文件浏览器访问它。由于无法执行此操作,因此我创建了一个更简单的应用程序,在该应用程序中,我仅创建一个文件并将其保存以查看其存储位置。但是无论我怎么做,我都看不到。
这是我的代码:
Calendar calendar = Calendar.getInstance();
String myFormat = "dd-MM-yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat,Locale.FRANCE);
String today = sdf.format(calendar.getTime());
//Obtiene ruta de sdcard
File pathToExternalStorage = Environment.getExternalStorageDirectory();
//agrega directorio /myFiles
File appDirectory = new File(pathToExternalStorage.getAbsolutePath() + "/biciMAPS/");
if ( !appDirectory.exists() ) {
if ( !appDirectory.mkdirs()) {
Toast.makeText(MainActivity.this,"could not create directory: " + appDirectory.getAbsolutePath(),Toast.LENGTH_LONG).show();
return;
}
}
//Crea archivo
File saveFilePath = new File(appDirectory,today + ".csv");
Log.i("AAARCHIVOOO",saveFilePath.getAbsolutePath());
这是Log.i显示的内容:
I/AAARCHIVOOO: /storage/emulated/0/biciMAPS/24-09-2020.csv
我使用了ES File Explorer,并且注意到/ storage / emulated / 0指向内部存储,但是找不到biciMAPS文件夹。
有什么主意吗?
谢谢!
解决方法
/storage/emulated/0
实际上是文件系统中的/data/media
。
就像您必须使用saveFilePath.createNewFile()
创建文件一样。
也许还添加了一些内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。