Search code examples
javaandroidfilekotlininternal-storage

How to move file a from internal storage of android?


I want to move a file from the android internal storage app-specific directory.
e.g: from /data/user/0/com.app.package/cache to /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?


Solution

  • 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 e.g. internal storage to SD