How to rename directory in Java

1 Answer

0 votes
package javaapplication1;

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

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            File oldName = new File("d://tmp");

            File newName = new File("d://tmp-old");

            boolean b = oldName.renameTo(newName);

            if (b) {
                System.out.println("Directory renamed");
            } else {
                System.out.println("Directory not renamed");
            }

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
Directory renamed
  
 */

 



answered Nov 19, 2016 by avibootz

Related questions

1 answer 211 views
211 views asked Aug 25, 2015 by avibootz
2 answers 300 views
300 views asked Aug 26, 2015 by avibootz
1 answer 172 views
3 answers 285 views
1 answer 201 views
1 answer 179 views
...