简体   繁体   English

如何从 android 的内部存储器中移动文件 a?

[英]How to move file a from internal storage of android?

I want to move a file from the android internal storage app-specific directory.我想从 android 内部存储应用程序特定目录中移动一个文件。
eg: from /data/user/0/com.app.package/cache to /data/user/0/com.app.package/files eg:/data/user/0/com.app.package/cache/data/user/0/com.app.package/files

I know I can copy all content and do stuff like reading bits, copy the content, re-write it to the new location and then delete the original one.我知道我可以复制所有内容并执行诸如读取位、复制内容、将其重新写入新位置然后删除原始位置之类的操作。
BUT
I don't want to do this, it's not moving but copying stuff.我不想这样做,它不是在移动,而是在复制东西。
So, does anyone knows here any simple method?那么,有人知道这里有什么简单的方法吗?

try to move with this code尝试使用此代码移动

File from = new File(oldPathWithFileName);
File to = new File(newPathWithFileName);
from.renameTo(to);

this should work only if both files are placed in same storage (thats your case), won't work when you want to move from eg internal storage to SD仅当两个文件都放置在同一存储中时才有效(这就是您的情况),当您想从例如内部存储移动到 SD 时将不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM