package com.heim.io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo5_Copy {
//拷贝的代码
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("双元.jpg"); //创建文件输入流对象,关联致双元.jpg
BufferedInputStream bis = new BufferedInputStream(fis); //创建缓冲区对fis装饰
FileOutputStream fos = new FileOutputStream("copy.jpg"); //创建输出流对象,关联copy.jpg
BufferedOutputStream bos = new BufferedOutputStream(fos); //创建缓冲区对fos装饰
int b;
while((b = bis.read()) != -1) {
bos.write(b);
}
bis.close(); //只关装饰后的对象即可
bos.close();
}
}
|
|