How to Rename a File on Sdcard with Android Application

Move/Rename file in SD Card

// this the uri, something like content://media/external/images/media/635

What you are then doing is trying to concatenate this onto Environment.getExternalStorageDirectory(). This will not work. content://media/external/images/media/635 is neither a relative filesystem path nor an absolute filesystem path. It is a Uri.

If you wish to copy the image from the Uri to a local file, use a ContentResolver to get an InputStream on the image represented by the Uri, then use Java I/O to copy the bytes from the InputStream to your target file.

Rename folder in SD card

File file = new File("your old file name");
File file2 = new File("your new file name");
boolean success = file.renameTo(file2);

android, How to rename a file?

The problem is in this line,

File from = new File(directory, "currentFileName");

Here currentFileName is actually a String you dont have to use "

try it this way,

File from      = new File(directory, currentFileName  );
^ ^ //You dont need quotes


Related Topics



Leave a reply



Submit