Sample Programs

Sample java program to move file or directory

 package org.jusfortechies.example; 

 public class MoveFile {

   public static void main(String[] args) {

     String movFile = "C:\\fileToBeMoved.txt";
     String toDir = "C:\\destDir";

     //File or Directory to be moved
     File file = new File(movFile);

     //Destination directory
     File dir = new File(toDir);

     //Move file to new location
     boolean success = file.renameTo(new File(dir, file.getName()));

     if (!success) {
       System.out.println("File was not moved to new directory");


blog comments powered by Disqus