Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package data;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import javax.swing.JProgressBar;
- public class MyRun implements Runnable {
- private String source;
- private String destination;
- private JProgressBar progressBar;
- public MyRun(String source, String destination, JProgressBar progressBar) {
- this.source = source;
- this.destination = destination;
- this.progressBar = progressBar;
- }
- @Override
- public void run() {
- {
- InputStream inStream = null;
- OutputStream outStream = null;
- try {
- File afile = new File(source);
- File bfile = new File(destination);
- inStream = new FileInputStream(afile);
- outStream = new FileOutputStream(bfile);
- progressBar.setMinimum(0);
- progressBar.setMaximum(100);
- long length = afile.length();
- long counter = 0;
- int r = 0;
- byte[] buffer = new byte[1024];
- while ((r = inStream.read(buffer)) != -1) {
- counter += r;
- progressBar.setValue((int) (100 * counter / length));
- outStream.write(buffer, 0, r);
- }
- inStream.close();
- outStream.close();
- System.out.println("Plik zostal skopiowany!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement