欢迎来到天天文库
浏览记录
ID:17021411
大小:12.34 KB
页数:3页
时间:2018-08-26
《java中缓冲读写buffer基础程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagecom.buffered;importjava.io.*;publicclassTestBufferedIO{publicstaticvoidmain(String[]args){Stringpath="d:/SQLHelp.java";TestBufferedIOt=newTestBufferedIO();try{//t.read2(path);//t.read3();//PrintStreamps=System.out;PrintStreamps=newPrintStream(newFile(
2、"d:/SQLHelp1.java"));t.list(path,ps);}catch(IOExceptione){e.printStackTrace();}}/***测试字节流的处理流**@parampath*@throwsIOException*/publicvoidread1(Stringpath)throwsIOException{Filef=newFile(path);InputStreamis=newFileInputStream(f);BufferedInputStreambis=newBuffe
3、redInputStream(is);byte[]bs=newbyte[20];intflag=-1;while((flag=bis.read(bs))!=-1){Stringmsg=newString(bs);System.out.print(msg);}bis.close();is.close();}/***测试打印流**@paramf*@paramfsotherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectoro
4、fthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmission
5、s,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand*/publicstaticvoidlist(Stringf,PrintStreamfs)throwsIOException{try{BufferedReaderbr=newBufferedReader(newFileReader(f));Strings=null;while((s=br.readLin
6、e())!=null){fs.println(s);}br.close();}catch(IOExceptione){fs.println("无法读取文件");}}/***测试字符流的处理流**@parampath*@throwsIOException*/publicvoidread2(Stringpath)throwsIOException{Filef=newFile(path);Readerreader=newFileReader(f);BufferedReaderbr=newBufferedReader(
7、reader);Stringmsg=null;while((msg=br.readLine())!=null){System.out.println(msg);}br.close();reader.close();}/***接收键盘输入*/publicvoidread3()throwsIOException{System.out.println("用户请输入内容:");InputStreamis=System.in;BufferedReaderreader=newBufferedReader(newInputS
8、treamReader(is));Stringmsg=null;while((msg=reader.readLine())!=null){System.out.println(msg);}reader.close();otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenew
此文档下载收益归作者所有