复制图片文件
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class BufferedIOputStreamDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream("android.jpg"));
bos = new BufferedOutputStream(new FileOutputStream("copy_android_buios.jpg"));
byte[] data = new byte[1024];
int len = 0;
while ((len = bis.read(data)) != -1) {
bos.write(data, 0, len);
}
} catch (Exception e) {
throw new RuntimeException("读写失败");
} finally {
try {
if (bis != null)
bis.close();
} catch (IOException e) {
throw new RuntimeException("读取关闭失败");
}
try {
if (bos != null)
bos.close();
} catch (IOException e) {
throw new RuntimeException("写入关闭失败");
}
}
}
}