用Java语言编写文件的复制

来源:互联网 发布:新海油网络论坛 编辑:程序博客网 时间:2024/06/03 18:38
public class FileCopy extends Thread{@Overridepublic 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 blocke.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();}}

0 0
原创粉丝点击