【发布时间】:2014-03-25 12:25:39
【问题描述】:
我尝试在平板电脑上创建目录并想查看它。
我用这段代码创建目录
public void createDirectory(String sDirectoryName) {
File direct = getDir(sDirectoryName, Context.MODE_PRIVATE);
File fileWithinMyDir = new File(direct, "myfile");
if(!direct.exist()) {
System.out.println("Directory created");
}
else {
System.out.println("Directory not created");
}
}
我每次创建目录时都会看到,但是当我在文件系统中搜索文件夹时,我看不到它。我怎样才能让它可见。我做错了吗?
编辑:
我已授予清单上的所有权限。我也试过这段代码
File direct = new File(Environment.getExternalStorageDirectory()+"/"+sDirectoryName);
if(!direct.exists())
{
if(direct.mkdir())
{
System.out.println("Directory created");
Toast.makeText(MainActivity.this, "Directory created", Toast.LENGTH_LONG).show();
}
else
{
System.out.println("Directory not created");
Toast.makeText(MainActivity.this, "Directory not created", Toast.LENGTH_LONG).show();
}
}
但这对我也不起作用。
编辑: 为了刷新,我使用此代码。
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
工作。
【问题讨论】: