Get your own Java server
import java.io.File;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    File myFile = new File("filename.txt");
    myFile.createNewFile();
    File newFile = new File("newname.txt");
    newFile.delete();  // Delete newname.txt if it already exists
    System.out.println(myFile.renameTo(newFile));
    System.out.println(myFile.exists());
    System.out.println(newFile.exists());
  }
}

              
true
false
true