package jbit.io;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;

public class ReadAndWriteBinaryImage {
	public static void main(String[] args) {
	  FileInputStream fis = null;
      DataInputStream dis = null;
      //创建输入流对象
      FileOutputStream outFile = null;
      DataOutputStream out = null;
	  try {
		  //创建输出流对象
	      fis = new FileInputStream("D:\\myDoc\\图10.2.BMP");
	      dis = new DataInputStream(fis);
	      //创建输入流对象
	      outFile = new FileOutputStream("D:\\myDoc\\temp2.BMP");
	      out = new DataOutputStream(outFile);
	      int temp;
	      //读取文件并写入文件
	      while ( (temp = dis.read()) != -1) {
	        out.write(temp);
	      }
	    }catch (IOException ioe) {
	      ioe.printStackTrace();
	    }finally{
	    	try {
	    		if(dis!=null)
	    			dis.close();
				if(out!=null)
					out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
	    }
	}
}