![](/img/trans.png)
[英]How to move/rename file from internal app storage to external storage on Android?
[英]How to move file a from internal storage of android?
我想從 android 內部存儲應用程序特定目錄中移動一個文件。
eg:
從/data/user/0/com.app.package/cache
到/data/user/0/com.app.package/files
我知道我可以復制所有內容並執行諸如讀取位、復制內容、將其重新寫入新位置然后刪除原始位置之類的操作。
但
我不想這樣做,它不是在移動,而是在復制東西。
那么,有人知道這里有什么簡單的方法嗎?
嘗試使用此代碼移動
File from = new File(oldPathWithFileName);
File to = new File(newPathWithFileName);
from.renameTo(to);
僅當兩個文件都放置在同一存儲中時才有效(這就是您的情況),當您想從例如內部存儲移動到 SD 時將不起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.