Moving a File or Directory to Another Directory - Java File Path IO

Java examples for File Path IO:Directory Move

Description

Moving a File or Directory to Another Directory

Demo Code

import java.io.File;

public class Main {
  public static void main(String[] argv) throws Exception {
    // File (or directory) to be moved
    File file = new File("filename");

    // Destination directory
    File dir = new File("directoryname");

    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
      // File was not successfully moved
    }/* w  w w  .j a v a  2 s  .c  o  m*/
  }
}

Related Tutorials