字节输入输出流读写
public static void main(String[] args) throws IOException {
// 1.创建字节输入流 关联数据源文件
FileInputStream fis = new FileInputStream("lib/1.png");
// 2.创建字节输出流 关联目的文件
FileOutputStream fos = new FileOutputStream("lib/1_bc.png");
// 3.定义变量 用于记录读取到的内容
int len;
// 4.循环读取 一旦满足条件就一直读
while((len = fis.read()) != -1) {
// 5.写入目的文件
fos.write(len);
}
// 6.关闭资源
fis.close();
fos.close();
}
字节缓冲输入流读写
public static void main(String[] args) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("lib/1.png"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("lib/1_bc.png"));
int len;
while((len = bis.read()) != -1) {
bos.write(len);
}
bis.close();
bos.close();
}