In my application, I need to record video. Before start of recording in I\'m assigning a name and directory to it. After recording is finished user has ability to rename his
you should check if the directory exist!
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), MEDIA_NAME);
if(!directory.exist()){
directory.mkdirs();
}
/**
* ReName any file
* @param oldName
* @param newName
*/
public static void renameFile(String oldName,String newName){
File dir = Environment.getExternalStorageDirectory();
if(dir.exists()){
File from = new File(dir,oldName);
File to = new File(dir,newName);
if(from.exists())
from.renameTo(to);
}
}
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