移动文件的SD卡 [英] Moving files in the sdcard
本文介绍了移动文件的SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图SD卡内,但无济于事移动文件:这里是code:
I have been trying to move files within the sd card but to no avail: Here is the code:
try {
File sd=Environment.getExternalStorageDirectory();
// File (or directory) to be moved
String sourcePath="mnt/sdcard/.Images/"+imageTitle;
File file = new File(sd,sourcePath);
// Destination directory
String destinationPath="mnt/sdcard/"+imageTitle;
File dir = new File(sd,destinationPath);
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
if (!success) {
handler.post(new Runnable(){
@Override
public void run() {
Toast.makeText(getApplicationContext(), "File moved", Toast.LENGTH_LONG).show();
}
});
}
}
catch (Exception e) {
}
我不知道wasup.Will AP preciate的帮助。
I dont know wasup.Will appreciate the help.
推荐答案
第一:如果你已经得到了外部目录,也没有必要将其添加到您的源路径$的开始C $ C>和
的DestinationPath
First: If you've gotten the external directory, there is no need to add it to the beginning of your sourcepath
and destinationpath
二,似乎的DestinationPath不必要的,因为它看起来像你只是想将其移动到SD卡的根文件夹。
Second, the destinationPath seems unnecessary as it looks like you just want to move it to the sdcard's root folder.
这应该是
File sd=Environment.getExternalStorageDirectory();
// File (or directory) to be moved
String sourcePath="/.Images/"+imageTitle;
File file = new File(sd,sourcePath);
// Destination directory
boolean success = file.renameTo(new File(sd, imageTitle));
这篇关于移动文件的SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文