hello to all. their is code for rename file but it not renaming file.

import java.io.*;
public class rename
{
public static void main(String[] args)
{
File f=new File("D:/lyerics/numb.txt");
File newName=new File("tumb.txt");
f.exists();
f.renameTo(newName);
System.out.print("new name is : "+f.getName());

}
}

give the correct code.

Comments

  • package com;

    import java.io.File;
    import java.io.IOException;

    public class FileRename {
    public static void main(String[] argv) throws IOException {

    // Construct the file object. Does NOT create a file on disk!
    File file = new File("E:\junk.txt"); // backup of this source file.

    // Rename the backup file to "junk.dat"
    // Renaming requires a File object for the target.
    file.renameTo(new File("E:\Tester2.java"));
    }
    }

    Try this
  • [color=Purple][b][size=3][u]thanks for reply.[/u][/size][/b][/color]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories