据推测,这一定是一项非常简单的任务,但我已经解决了一段时间但没有成功...
在我的应用程序中,我在 SD 卡中创建了一个文件夹,用于存储临时 jpg 文件。由于我不希望我的应用程序在浏览手机图像时显示这些临时文件,因此我试图隐藏该文件夹。所以,在创建目录之后,我尝试重命名它,如下所示:
String tmppath="/sdcard/myapp/tmp";
try
{
//this creates a directory named TMP -->OK!
File f=new File(tmppath);
if(!f.isDirectory())
f.mkdirs();
//this was supposed to rename the directory to .TMP, but isn't working...
Process process=Runtime.getRuntime().exec("mv "+tmppath +" /sdcard/myapp/.tmp/");
process.waitFor();
}
catch(SecurityException e)
{
}
catch(IOException e)
{
}
catch (InterruptedException e)
{
}
有什么想法吗?
最佳答案
File file = new File("your old file name");
File file2 = new File("your new file name");
boolean success = file.renameTo(file2);
关于android - 重命名 SD 卡中的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5856725/