我尝试将文件从一个文件夹移动到另一个文件夹,如下所示:
File fileFrom = new File("/storage/1AF5-2B0F/test/testfile");
File fileTo = new File("/storage/1AF5-2B0F/test2/testfile");
boolean moveok = fileFrom.renameTo(fileTo);
moveok是假的
当使用内部SD卡进行相同操作时,它可以正常工作。如何在外部SD卡上移动文件?
我有写权限
android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
答案 0 :(得分:1)
使用Environment.getExternalStorageDirectory()
转到external storage
(SD)
File from = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"1AF5-2B0F/test/testfile.jpg");
File to = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/1AF5-2B0F/test2/testfile.jpg");
boolean moveok = from.renameTo(to);
答案 1 :(得分:0)
问题可能出在外部SD卡目录中。
File from = new File(/storage/1AF5-2B0F/test/testfile");
// You can use the Environment.getExternalStorageDirectory() to get to the root of external storage (which, on some devices, is an SD card).
File to = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/test/testfile");
from.renameTo(to);