Android在文件资源管理器

时间:2017-03-04 10:39:50

标签: java android

我正在使用以下代码创建文件夹:

File f = new File(Environment.getExternalStorageDirectory(), folder_main);
if (!f.exists()) {
    f.mkdirs();
    this.showDialog("Done");
}
else{
    this.showDialog("Exist");
}

此代码显示Exist和Done正确,但是当我使用文件浏览器转到SD卡时,我看不到创建的文件夹。为什么以及如何使其发挥作用?

1 个答案:

答案 0 :(得分:1)

我的意思是,试试这个(确保f目前不存在):

File f = new File(Environment.getExternalStorageDirectory(), folder_main);
if (!f.exists() && f.mkdirs()) {
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(f)));
    this.showDialog("Done");
}else{
    this.showDialog("Exist");
}