How to Move file in the same storage by changing path sytem level Android

How to move file not copy by just changing the path of file system level in android I have path like this

File f = new File(/storage/Folder1/Folder2/image.png);

File newfile = new File((/storage/Folder3/image.png);

I want to change the path of f to newfile without coping because it takes time and system give us support if we are in same mount point we can move file super fast just like if we move file in dextop windows in the same drive then speed is so fast I want to achieve same thing

Please give some sample code.

Upvotes: 0

Views: 189

Answers (1)

laune
laune

Reputation: 31290

You can use Files.move, with options for retaining file attributes and detailed error reporting via several exceptions:

try {
    Files.move( f.toPath(), newFile.toPath() );
} catch(...){
    ...
}

Possibly also the simpler method works for you, although this is more implementation dependent:

f.rename( newFile );

Upvotes: 1

Related Questions