import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class fanxing {
public static void main(String args[]) throws IOException {
// method_read_one();
// method_read_two();
// method_copy();
method_buff_copy();
}
public static void method_writer() throws IOException{
FileOutputStream fos=new FileOutputStream("fos.txt");
String s="sdafesgerhggber";
fos.write(s.getBytes());
fos.close();
}
public static void method_read_one() throws IOException{
FileInputStream fin=new FileInputStream("fos.txt");
int len=0;
while((len=fin.read())!=-1){
System.out.print((char)len);
}
fin.close();
}
public static void method_read_two() throws IOException{
FileInputStream fin=new FileInputStream("fos.txt");
byte[] arr=new byte[1024];
int len=0;
while((len=fin.read(arr))!=-1){
System.out.print(new String(arr,0,len));
}
fin.close();
}
public static void method_copy() throws IOException{
FileInputStream fin=new FileInputStream("pic.jpg");
FileOutputStream fos=new FileOutputStream("zhpu.jpg");
byte[] arr=new byte[1024];
int len=0;
while((len=fin.read(arr))!=-1){
fos.write(arr,0,len);
}
fin.close();
fos.close();
}
public static void method_buff_copy() throws IOException{
BufferedInputStream buffis=new BufferedInputStream(new FileInputStream("pic.jpg"));
BufferedOutputStream buffos=new BufferedOutputStream(new FileOutputStream("zhpu.jpg"));
int len=0;
while((len=buffis.read())!=-1){
buffos.write(len);
}
buffis.close();
buffos.close();
}
}
Java_字节流的读写copy,bufferedinputstream等
最新推荐文章于 2022-09-06 19:52:07 发布
本文展示了如何使用Java的字节流进行文件操作,包括简单读写、文件复制以及使用BufferedInputStream和BufferedOutputStream进行缓冲复制,提高效率。
摘要由CSDN通过智能技术生成