Tuesday, December 06, 2011

Renaming a File or Directory

The following code will rename the file/directory.Here 'FileOrDirNameBefore' is the directory name to be renamed to 'FileOrDirNameAfter'.
  1. File f1= new File("FileOrDirNameBefore");
  2. File f2= new File("FileOrDirNameAfter");
  3. boolean success = f1.renameTo(f2);
  4. if (!success) {
  5.     // File was not successfully renamed
  6. }

No comments:

Post a Comment