How do I rename a file or directory?

Bookmark this example!  
Category: java.io, viewed: 1724 time(s).
 
package org.kodejava.sample.java.io;
 
import java.io.File;
import java.io.IOException;
 
public class FileRenameExample
{
    public static void main(String[] args) throws IOException
    {
        // This will create a new file called OldHouses.csv
        File oldFile = new File("OldHouses.csv");
        oldFile.createNewFile();
        
        // Here we create a new instance of File that we gonna use
        // to rename the old file to the new one.
        File newFile = new File("NewHouses.csv");
 
        // The renameTo() method renames file or directory to a
        // new name by passing the new destination file.
        oldFile.renameTo(newFile);
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats