Dir*_*tad 4 directory android rename
据说这应该是一项非常简单的任务,但我已经有一段时间没有成功......
在我的应用程序中,我在SD卡中创建了一个文件夹,我存储了临时的jpg文件.由于我不希望我的应用程序在浏览手机图像时显示这些临时文件,因此我试图隐藏该文件夹.所以,在创建dir后,我尝试重命名它,如下所示:
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)
{
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
Piy*_*ush 15
File file = new File("your old file name");
File file2 = new File("your new file name");
boolean success = file.renameTo(file2);
Run Code Online (Sandbox Code Playgroud)
小智 6
final File F=new File("youroldpath");
String newname="newname";
File newfile=new File(F.getParent(),newname);
F.renameTo(newfile);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9143 次 |
| 最近记录: |