public static void copy
(File source,
File dest
) throws IOException {
FileChannel in =
null, out =
null;
try {
in =
new FileInputStream(source
).
getChannel();
out =
new FileOutputStream(dest
).
getChannel();
in.
transferTo( 0, in.
size(), out
);
} finally {
if (in !=
null) {
in.
close();
}
if (out !=
null){
out.
close();
}
}
}
public static void xCopyDir
(String sourceFolder,
String destinyFolder
)
throws IOException{
if (!
new File(sourceFolder
).
isDirectory()){
throw new IOException("Source Directory error ");
}
boolean success =
(new File(destinyFolder
)).
mkdirs();
if (!
new File(destinyFolder
).
isDirectory()){
throw new IOException("Destini Directory error ");
}
copyRecursiveDir
(sourceFolder, destinyFolder
);
}
private static void copyRecursiveDir
(String sourceFolder,
String destinyFolder
)
throws IOException{
File file;
String list
[];
file =
new File(sourceFolder
);
if (file.
isDirectory()) {
list = file.
list();
for (int i =
0; i < list.
length; i++
){
if ( !
new File(sourceFolder +
File.
separatorChar + list
[i
]).
isFile()){
boolean success =
(new File(destinyFolder +
File.
separatorChar + list
[i
])).
mkdirs();
}
copyRecursiveDir
(sourceFolder +
File.
separatorChar + list
[i
],
destinyFolder +
File.
separatorChar + list
[i
]);
}
}
if(new File(sourceFolder
).
isFile()){
copy
(new File(sourceFolder
),
new File(destinyFolder
) );
}
}