0

My Question is how to move file not copy by just changing the path of file system level
in android file.nenameTo(newpath); this method works only when I have path like this

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

f.renameTo(newfile);  // this method returns true

it works but when more then one parent folder change then it's not working

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

f.renameTo(newfile); // this method returns false

the following case also not work 

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

f.renameTo(newfile); // this method returns false

I want to move file like above
sorry for my English

1 Answers1

1

You can only rename a file in Android if the src and dst are on the same mount point. You don't specify either way. Please consider using Files.move instead to avoid this potential issue and others.

  • Please read my Question it's mention that i have same mount point like Path 1 :/storage/Folder1/Folder2/image.png Path2 :/storage/Folder3/Folder4/image.png – Muhammad Waqas Khan Abbasi Dec 23 '14 at 11:49
  • I read the question again. You simply do not state that the mount point is the same. "In the same storage" doesn't address this issue. /storage/Folder1 could be on one partition while /storage/Folder3 is on another. If the mount point is the same and the folder is there I would look hard at permissions. – William Deans Dec 23 '14 at 11:55