I am new to Swing Applications.
I have a simple app that copies files from a directory to another one. To copy the files I use FileChannel
instances. I was wondering if it is possible to show a progress bar to inform the user How much of the files have been copied.
Here is my code:
public class Foo extends JFrame{
long size;
FileChannel inp = null,
outp= null;
File sourceFile = new File("C:/test/movie.mkv"),
destFile = new File("C:/output/movie.mkv");
public void createUI(){
JPanel panel = new JPanel();
JButton btn = new JButton("Copy Files");
panel.add(btn);
/*code to create and position the jframe*/
btn.addActionListener((e)->{
try {
inp = new FileInputStream(sourceFile).getChannel();
outp = new FileOutputStream(destFile).getChannel();
size = inp.size();
outp.transferFrom(inp,0,size);
} catch (Exception e2) {
System.out.println("FIle not found");
return;
}
});
}
public static void main(String[] args) {
SwingUtilities.invokeLater(()->new Foo().createUI());
}
}