Answers for "renaming existing file in java"

1

How to rename file in java

// rename file in java example
import java.io.*;
public class RenameFile
{
   public static void main(String[] args) throws IOException
   {
      File oldFile = new File("D:\\Project\\flower.txt");
      File newFile = new File("D:\\Project\\flowerbrackets.txt");
      if(oldFile.renameTo(newFile))
      {
         System.out.println("Rename successful");
      }
      else
      {
         System.out.println("Rename failed");
      }
   }
}
Posted by: Guest on December-10-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language