Move a file from one directory to another - Java File Path IO

Java examples for File Path IO:File Move

Description

Move a file from one directory to another

Demo Code

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

public class Main {
  public static void main(String[] arg) throws IOException {

    File f = new File("logs\\myfile.txt");
    if (f.renameTo(new File("savedlogs\\myfile.txt")))
          System.out.println("File moved.");
    else/*from  ww w.j a  v a 2s.  c om*/
          System.out.println("File not moved.");


  }
}

Related Tutorials