tolcas的博客

Remember the time

用Java语言编写文件的复制

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();
	}
}


阅读更多
个人分类: Java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭