Need to have JProgress bar to measure progress when copying directories and files
Posted
by
user1815823
on Stack Overflow
See other posts from Stack Overflow
or by user1815823
Published on 2012-11-26T22:45:54Z
Indexed on
2012/11/26
23:04 UTC
Read the original article
Hit count: 173
I have the below code to copy directories and files but not sure where to measure the progress. Can someone help
as to where can I measure how much has been copied and show it in the JProgress bar
public static void copy(File src, File dest)
throws IOException{
if(src.isDirectory()){
if(!dest.exists()){ //checking whether destination directory exisits
dest.mkdir();
System.out.println("Directory copied from "
+ src + " to " + dest);
}
String files[] = src.list();
for (String file : files) {
File srcFile = new File(src, file);
File destFile = new File(dest, file);
copyFolder(srcFile,destFile);
}
}else{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0){
out.write(buffer, 0, length);
}
in.close();
out.close();
System.out.println("File copied from " + src + " to " + dest);
}
© Stack Overflow or respective owner