How to display the file name & status when copying files.
I write a program to backup/copy data from one directory to other directory, and I'm using File List and Runtime.getRuntime().exec("xcopy "+dir1+"\\"+name+" "+dir2+" /y");
to copy the files, so it will copy the file one by one, and everytime one file is copied, I want to display the result to the screen, but guess what has happened, the screen just display a blank screen, and wait until all the copying processes finish, then it will display all files that has been copied.
Appreciate your expertise to check my coding below.
String[] fileList = fbackupSource.list();
boolean done=true;
JTextArea backupText = new JTextArea();
JScrollPane backupScroll = new JScrollPane(backupText,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JFrame backupWindow = new JFrame("Backup Data");
backupWindow.setBounds(320,240,400,330);
backupWindow.getContentPane().add(backupScroll);
backupText.setText("Copy files from "+backupSource.toUpperCase()+" to "+backupDest.toUpperCase()+" : \n\n");
backupWindow.show();
for (int i=0; i < fileList.length; i++) {
backupText.append(" ("+ i +")... processing " + fileList);
done = copyFile(fileList,backupSource,backupDest);
if (done=true) {
backupText.append(" -> done. \n");
}
else {
backupText.append(" -> fail! \n");
}
}
boolean copyFile(String name, String dir1, String dir2) {
try {
java.lang.Process proc =
Runtime.getRuntime().exec("xcopy "+dir1+"\\"+name+" "+dir2+" /y");
proc.waitFor();
return true;
}
catch (IOException e) {
return false;
}
catch (InterruptedException e) {
return false;
}
}

