3:11 pm - Monday November 23, 6499

To change the name of a file using renameTo()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This tutorial explains how To change the name of a file using renameTo() method,To create a file in java, ‘File.createNewFile()’ method is used,it returns a boolean value, true if the file is created successfully false otherwise.


import java.io.File;

public class FileRename

{

public static void main(String[] args)

{

boolean bool = false;

File f = new File("/home/mathan/Documents/abcd.txt");

File f1 = new File("/home/mathan/Documents/abcd1.txt");

bool = f.renameTo(f1);

System.out.print("File renamed? " + bool);

}

}

Output

File renamed? false

BACK

Filed in: Java Examples

Comments are closed.