Moving File
      This program illustrates how to move a file from one directory to another.
/*
	http://www.ProbCOMP.com
	
	This program illustrates how to move a file from one directory 
	to another.

*/

import java.io.File;
	// Move File, Directory to another Directory
public class MoveFileDir {
	public static void main(String args[]){

        // enter first the names of files as command line argument , first write the oldfile name and then the new directory name e.g.
			// java RenameFileDir oldfile.txt newdir
        
		File file = new File(args[0]);
			File dir = new File("./"+args[1]); // destination directory
		
		//The File constructor Creates a new File instance from a parent abstract pathname and a child pathname string.
		File f = new File(dir, file.getName());
		
		boolean move= file.renameTo(f); 
		 if (move)
		 {
             System.out.println("File was successfully moved.\n");
         } 
		 else 
		 {
             System.out.println("File was not successfully moved.\n");
         }


    }
}
									

Download Program
Did You Know ?
IP address is a numerical label that is assigned to devices participating in a computer network. Read More