Results 1 to 2 of 2
  1. #1
    Ada
    Ada is offline Member
    Join Date
    May 2007
    Posts
    8
    Rep Power
    0

    Default How to Rename a File

    I also want to rename a file in Java. How can i do that?

  2. #2
    FaRuK is offline Member
    Join Date
    May 2007
    Posts
    7
    Rep Power
    0

    Default

    Hi Ada,

    You can use following code segment to rename a file:

    Java Code:
        // File (or directory) with old name
        File file = new File("oldname");
        
        // File (or directory) with new name
        File file2 = new File("newname");
        
        // Rename file (or directory)
        boolean success = file.renameTo(file2);
        if (!success) {
            // File was not successfully renamed
        }
    File class has several similar useful methods. I reccomend you to check them:

    File (Java 2 Platform SE v1.4.2)

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 05:01 PM
  2. Replies: 2
    Last Post: 04-07-2009, 07:25 AM
  3. How to rename a file
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-05-2008, 11:11 AM
  4. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 AM
  5. how to rename a subdirectory
    By richardzhang in forum New To Java
    Replies: 0
    Last Post: 08-10-2007, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •