Reputation: 133
My problem is to cut out an image from a folder and paste that image in another folder. I've searched but have not been able to implement this problem!
for example:
File file1 = new File("mnt/sdcard/kaic1/imagem.jpg");
for
File file2 = new File("mnt/sdcard/Kaic2/");
Upvotes: 0
Views: 3791
Reputation: 572
Try this:
File file1 = new File("mnt/sdcard/kaic1/imagem.jpg");
File file2 = new File("mnt/sdcard/Kaic2/imagem.jpg");
file1.renameTo(file2);
Here's more info on the renameTo
function:
http://developer.android.com/reference/java/io/File.html#renameTo(java.io.File)
Edit: also check Osmium USA's answer regarding hard-coding the "mnt/sdcard/" folder path in your code.
Upvotes: 2
Reputation: 1786
A better solution to this problem would be:
File from = new File(Environment.getExternalStorage().getAbsolutePath()+"/kaic1/imagem.jpg");
File to = new File(Environment.getExternalStorage().getAbsolutePath()+"/kaic2/imagem.jpg");
from.renameTo(to);
You can't assume that the sdcard is at /mnt/sdcard
. Newer devices, such as a Nexus four, don't even have sdcards. Their storage is at /storage/emulated/0
. It's always better to ask the OS where something is than to make assumptions (as ethan pointed out.)
Upvotes: 6