Wednesday, May 9, 2012

How to rename file in java with example

How to rename file in java with example
import java.io.File;

public class FileRenameExample 
{
    public static void main(String[] args)
    { 
 
  File oldFileName =new File("D:\\db\\fileTest\\file1.txt");
  File newFileName =new File("D:\\db\\fileTest\\file2.txt");
 
  if(oldFileName.renameTo(newFileName))
  {
   System.out.println("File Renamed successfully");
  }
  else
  {
   System.out.println("Can not rename file");
  }
    }
}

No comments:

Post a Comment