1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| private class MyWorker extends SwingWorker<Void, Void> {
private String src;
private String dest;
private Cop _cop;
public MyWorker(String src, String dest) {
this.src = src;
this.dest = dest;
// this.addPropertyChangeListener(new WorkerListener());
}
@Override
protected Void doInBackground() throws Exception {
_cop = new Cop(null, true);
_cop.show();
copi(src, dest);
return null;
}
@Override
protected void done() {
try {
_cop.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
private void copi(String src,String dst){
InputStream inStream = null;
OutputStream outStream = null;
try{
File afile =new File(src);
File bfile =new File("images\\"+dst);
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
while ((length = inStream.read(buffer)) > 0){
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
}catch(IOException e){
e.printStackTrace();
}
}
} |
Partager