Tuesday, May 10, 2011

Copy multiple files (java)

We have already seen the function to copy 1 file to another destination. Here we have to write function to copy multiple file to 1 location.

Refer this article for copyFile() function.

public static boolean copyMultipleFiles(String dst, String ... src){
for(String oneSrc : src)
{
boolean isCopied = copyFile(oneSrc,dst);
if(!isCopied)
return isCopied;
//Note that i have not yet figured out the case of rollback in case of
//unsuccessful copy of 1 file. Because this depends on your application.
//So if you want to rule out any copy if even 1 copy file fails,
//just call the delete function and so on.
}
return true;
}



Also note that this method uses varargs function, but you can use array instead.

No comments:

Post a Comment

Chitika