how-to

File & Directory

How to rename file

For working with files you need to use:

import java.io.*;

For file renaming use function java.io.File.rename(). It is useful to check if the new file name not exists.

File f = new File( "c:\\new_name.txt" );

if ( f.exists() ) {

  /* override question ? */

  f.delete();
}

boolean b = new File( "c:\\old_name.txt" ).renameTo( f );