The following code 'll copy the contents of a given source folder to a given destination folder.This method accepts 2 parameters,one for source folder location and another for destination folder location.
- if(!srcFolder.exists()){
- }
- //If folder/directory
- if(srcFolder.isDirectory()){
- //If destination directory doesn't exist, create it
- if(!destFolder.exists()){
- destFolder.mkdir();
- }
- //List all the contents of source directory
- //construct the srcFolder and destFolder file structure
- //recursive copy
- copyFolder(srcFile,destFile);
- }
- }
- //If file, then copy it
- else{
- //Use bytes stream to support all file types
- byte[] buffer = new byte[1024];
- int length;
- //copy the file content in bytes
- while ((length = in.read(buffer)) > 0){
- out.write(buffer, 0, length);
- }
- in.close();
- out.close();
- }
- }
No comments:
Post a Comment