2017-02-17 97 views
-1

我試着從一個文件夾移動文件到另一個如下:移動文件(外部SD卡)

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

你確定'test2'目錄是否存在? – zed

+0

是的,它存在。 100%。 –

+0

這個問題有什麼問題。請評論爲什麼downvoting,如果你敢:-) –

回答

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); 

Reference

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);