moving files in java - TechRepublic
General discussion
June 11, 2001 at 03:51 AM
ashapoo_jain

moving files in java

by ashapoo_jain . Updated 24 years, 11 months ago

I want to move files from one folder to another in Java. I used the renameTo method in the File class but that doesnt helps me…
Am posting my code here, can some one look at it and tell me whats wring in it and also is there an efficient way to move files in Java across folders…

public boolean moveFiles(String source, String destination)
{
//This method moves the files from one directory to another
File sourceDir = new File(source.trim());
File destinationDir = new File(destination.trim());

boolean created = true;
if(!destinationDir.exists())
{
//Create that directory

created = destinationDir.mkdir();
System.out.println(“The directory created ” + created);

//do the moving of files here

File [] tmp = sourceDir.listFiles();
for(int i =0;i

This discussion is locked

All Comments