资源描述:
《java_IO流总结》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、********************************第19天IO流*************************************************************基本内容*****************************字符流:Reader常用子类:InputStreamReader->(继承)FileReader,BufferedReaderWriter常用子类:OutputStreamWriter->(继承)FileWriter,BufferedWriter字节流:OutputStream常用子类:File
2、OutputStream,DataOutputStream,ObjectOutputStream,BufferedOutputStream,ByteArrayOutputStreamInputStream常用子类:FileInputStream,DataInputStream,ObjectOutputStream,BufferedInputStream,ByteArrayInputStream打印流:PrintStream常用子对象:System.out,System.in,System.err===============================
3、===============================================================********************************字节流:OutputStream,InputStream********************************一、字节流: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流关闭异常fis.close();fos.close();}catch(Exceptione2){}}}}二、字节缓冲流: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.