测试:使用DataInputStream和DataOutputStream完成.class文件的copy

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/** * 使用DataInputStream和OutputStream读写文件 * * @Hudie */
public class ReadAndWrite {
	public static void main(String[] args) {
		// 1.创建流
		DataInputStream dis = null;
		DataOutputStream dos = null;
		try {
			dis = new DataInputStream(new FileInputStream("E:/java/workspace/com.ql/bin/june_1th/Sale.class"));
			dos = new DataOutputStream(new FileOutputStream("f:/fileCopy.class"));
			// 2.实现读写操作
			int temp;
			while ((temp = dis.read()) != -1) {
				dos.write(temp);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (dis != null) {
				try {
					dis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (dos != null) {
				try {
					dos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}

运行后在f盘成功copy了一个e盘下的class文件: