資源描述:
《java_IO流總結(jié)》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、********************************第19天IO流*************************************************************基本內(nèi)容*****************************字符流:Reader常用子類:InputStreamReader->(繼承)FileReader,BufferedReaderWriter常用子類:OutputStreamWriter->(繼承)FileWriter,BufferedWriter字節(jié)流:OutputStream常用子類:File
2、OutputStream,DataOutputStream,ObjectOutputStream,BufferedOutputStream,ByteArrayOutputStreamInputStream常用子類:FileInputStream,DataInputStream,ObjectOutputStream,BufferedInputStream,ByteArrayInputStream打印流:PrintStream常用子對象:System.out,System.in,System.err===============================
3、===============================================================********************************字節(jié)流:OutputStream,InputStream********************************一、字節(jié)流:FileInputStream,FileInputStream//文件讀寫importjava.io.*;publicclassText1{publicstaticvoidmain(String[]args){FileInputStream
4、fis=null;FileInputStreamfos=null;try{fis=newFileInputStream("e:\temp\from.zip");fos=newFileOutputStream("e:\temp\to.zip");byte[]buffer=newbyte[1024];while(true){inttemp=fis.read(buffer,0,buffer.length);if(temp==-1){break;}fos.write(buffer,0,temp);}}catch(Exceptione){e.printSta
5、ckTrace();}finally{try{//捕獲io流關(guān)閉異常fis.close();fos.close();}catch(Exceptione2){}}}}二、字節(jié)緩沖流:BufferedInputStream,BufferedOutputStream--------------------------------------//文件讀寫publicclassText2{publicstaticvoidmain(String[]args){StringfileName="e:\老羅視頻Android01-09.zip";StringtoName=
6、"e:\temp\老羅視頻Android01-09.zip";FileInputStreamfis=null;FileOutputStreamfos=null;BufferedInputStreambis=null;BufferedOutputStreambos=null;try{fis=newFileInputStream(fileName);fos=newFileOutputStream(toName);bis=newBufferedInputStream(fis);bos=newBufferedOutputStream(fos);longtime
7、1=System.currentTimeMillis();//打印時間while(true){byte[]buffer=newbyte[1024];inttemp=bis.read(buffer,0,buffer.length);if(temp==-1){break;}bos.write(buffer,0,temp);}longtime2=System.currentTimeMillis();System.out.println((time2-time1)/60000);//求時間差}catch(IOExceptione){e.printStackTrac
8、e();}finally{try{bis.close();bos.