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 203 views
203 views asked Aug 25, 2015 by avibootz
2 answers 292 views
292 views asked Aug 26, 2015 by avibootz
1 answer 159 views
3 answers 274 views
1 answer 188 views
1 answer 165 views
...