public class FileCopy extends Thread{
@Override
public void run() {
File first = new File("d:/hello.mp3");
File second = new File("e:hello.mp3");
while(first.length() != second.length()){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("完成了:" + ((int)(10000 * second.length() / first.length())) / 100.0 + "%");
}
}
}
public class Test {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("d:/hello.mp3");
DataInputStream dis = new DataInputStream(fis);
FileOutputStream fos = new FileOutputStream("e:/hello.mp3");
DataOutputStream dos = new DataOutputStream(fos);
FileCopy fc = new FileCopy();
fc.start();
int data;
while((data = dis.read()) >= 0){
dos.write(data);
}
dos.close();
fos.close();
dis.close();
fis.close();
}
}