字节流一般用于对图片,音乐等文件的操作。
字节输入流:FileInputStream
字节输出流:FileOutputStream
package Io;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageCope {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("test.jpg");
//字节输出流
FileOutputStream fos = new FileOutputStream("new.jpg");
int a=0;
while((a=fis.read()) != -1){
fos.write(a);
}
fos.flush();
fis.close();
fos.close();
}
}
缓冲字节输入流:BufferedInputStream,用来读取数据。
缓冲字节输出流:BufferedOutputStream,用来写入数据。
package Io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class BfISDemo {
public static void main(String[] args) throws IOException {
//字节输入流,用来读取内容
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("new.jpg"));
//字节输出流,用来写入数据
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("new2.jpg"));
int a=0;
while((a=bis.read()) != -1)
bos.write(a);
bos.flush();
bis.close();
bos.close();
}
}