字节流、字符流、缓冲流

字节流:

FileInputStream明确数据源,FileOutputStream明确目的地

FileInputStream fis=new FileInputStream("D:\\aaa\\aaa.rar");
FileOutputStream foss=new FileOutputStream("D:\\bbb\\aaa\\aaa.txt");
int len=0;

//单个字节
while((len=fis.read())!=-1){
fos.write(len);
}

//字节数组

byte[] bytes=new byte[1024];
while((len=fis.read(bytes))!=-1){
fos.write(bytes,0,len);
}

字符流:

FileReader

FileWriter

//字节+缓冲流:

BufferedInputStream,BufferedOutputStream

new BufferedInputStream(fos)

new BufferedOutputStream(fis)

posted on 2019-10-21 11:09  流光若影  阅读(113)  评论(0编辑  收藏  举报