How to rename file in java? How to change file name in java?

Below java code shows how to rename a file or change a file name

* Created on 10-2011 Copyright(c) All Rights Reserved.
package com.kodehelp.javaio;


* Created by
* Date: 10/3/11
public class RenameFile {
public static void main(String args[]){
File file = new File("/conf.txt");

if (!file.exists() || file.isDirectory()) {
System.out.println("File does not exist: " + file);

File newFile = new File("/conf.ini");

if (file.renameTo(newFile)) {
System.out.println("File has been renamed.");
} else {
System.out.println("Error renmaing file");

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.