package chapter08
import java.io.*;
public class TestFileOutputStream {
	public static void main(String[] args) throws FileNotFoundException	{
		FileInputStream fileIn=new FileInputStream("Sunset.jpg");
		FileOutputStream fileOut=new FileOutputStream("Sunset1.jpg");
		byte[] buffer=new byte[1024];
		// ÿζȡдĶƳ
		int len=1024;
		// ÿζȡдĿʼλ
		int startPos=0;
		try {
			// ļĿͷλöȡlenֽڵݵbuffer
			int end=fileIn.read(buffer,startPos,len);
			// Ƿ񵽴ļĩβ
			while(end!=-1){
				fileOut.write(buffer);
				end=fileIn.read(buffer,startPos,len);
			}
			fileOut.flush();
			fileIn.close();
			fileOut.close();
		} 
catch (IOException e) {
			e.printStackTrace();		}	
	}
}
