1. 程式人生 > 資訊 >拯救蘇寧易購迎變局:江蘇國資接盤、深圳退出

拯救蘇寧易購迎變局:江蘇國資接盤、深圳退出

IO流:概括為兩個對應,一個橋樑。

1.按照功能來劃分:
輸入流:只能從中讀取資料,而不能向其寫入資料。
輸出流:只能向其寫入資料,而不能從中讀取資料。
2.按照處理單元來劃分
位元組流和字元流操作的方式基本上完全相同。操作的資料單元不同
位元組流:操作的是8位的位元組InputStream/OutputStream作為位元組流的基類
字元流:操作的是16位的字元Reader/Writer作為字元流的基類

FileinputstreamFileOutputStream不帶緩衝區的位元組流

publicstaticvoidmain(String[]args){
try{
FileInputStream fis =newFileInputStream("D:\\img1.jpg");
FileOutputStreamfos=newFileOutputStream("D:\\img2.jpg");
byte[]b=newbyte[1024];
int l=0;
while((l = fis.read(b) )!=-1){
fos.write(b,0,a);
}
}catch(IOExceptione){
e.printStackTrace();
}

}

BufferedInputStreambufferedOutputStream帶緩衝區的位元組流

publicstaticvoidmain(String[]args){

try{
FileInputStreamfis=newFileInputStream("d:\\img2.jpg");
FileOutputStreamfos=newFileOutputStream("d:\\zxs.jpg");
BufferedInputStreambis=newBufferedInputStream(fis);
BufferedOutputStreambos=newBufferedOutputStream(fos);
byte[]b=newbyte[1024];
int l =0;
while((l = fis.read(b) )!= -1){
bos.write(b,0,a);
}
}catch(FileNotFoundExceptione){
e.printStackTrace();
}catch(IOExceptione){
e.printStackTrace();
}

}

FileReaderFileWriter不帶緩衝區的字元流

BufferedReaderBufferedWriter帶緩衝區的位元組流