《Java的输入与输出流(实验报告)》由会员分享,可在线阅读,更多相关《Java的输入与输出流(实验报告)(10页珍藏版)》请在金锄头文库上搜索。
1、成都大学实验报告姓名系别班级学号:课程名称P指导教师实验成绩实验日期JAVA程序设计基础实验项目名称Java的输入与输出流、实验目的:1、理解I/O流的卞s念,掌握其分类2、掌握文本文件读写、二进制文件读写二、实验内容(包括源程序及相关说明):1、分别使用与BuferedWriter往文件中写入10万个随机数,比较用时。源代码如下:importjava、io、*;publicclassEx1_1publicstaticvoidmain(String口args)throwsIOExceptionlongt=System、currentTimeMillis();fw=new(d:Ex1、txt);
2、for(inti=1;i=100000;i+)fw、write(int)(Math、random()*10000)+n);fw、close();t=System、currentTimeMillis()-t;+t);throws IOExceptionSystem、out、println(Theelapsed:importjava、io、*;publicclassEx1_1publicstaticvoidmain(String口args)longt=System、currentTimeMillis();BufferedWriter fw=new BufferedWriter(new ( d:Ex
3、1、txt);for(inti=1;i=100000;i+)fw、write(int)(Math、random()*10000)+n);fw、close();t=System、currentTimeMillis()-t;System、out、println(Theelapsed:+t);2、生成一个html文件,使其能显示2的幕次(09)的表格如下:Powerof2Value0011代码如下:importjava、io、*;publicclassEx1_1publicstaticvoidmain(String口args)throwsIOExceptionBufferedWriterbw=new
4、BufferedWriter(new(d:Ex2、html);bw、write();bw、newLine();bw、write(Powerof2Value);for(inti=0;i=9;i+)bw、write(+i+Math、pow(i,2)+);bw、write();bw、newLine();bw、close();3、在文本文件bigbook、txt中包含有很长篇幅的英语短文,编写程序要求统计文件的所有短文中包含英文字母“A”的个数,并显示统计的时间。第一种实现方法代码如下:importjava、io、;importjava、io、IOException;publicclassEXP1_1
5、publicstaticvoidmain(String口args)throwsIOExceptionlongt=System、currentTimeMillis();StringD:bigbook、txtfis=new();intcount=0;intc;while(c=fis、read()!=-1)if(c=A)count+;fis、close();System、out、println(count);t=System、currentTimeMillis()-t;System、out、println(Timelapsed:+t);第二种方法代码如下:importjava、io、;importj
6、ava、io、IOException;importjava、io、BufferedInputStream;publicclassEXP1_1publicstaticvoidmain(String口args)throwsIOExceptionlongt=System、currentTimeMillis();StringD:bigbook、txt;fis=new();BufferedInputStreambis=newBufferedInputStream(fis);intcount=0;intc;while(c=bis、read()!=-1)if(c=A)count+;fis、close();S
7、ystem、out、println(count);t=System、currentTimeMillis()-t;System、out、println(Timelapsed:+t);、实验结果:Powerof2Value0J0.011.02里039.0416.0525.0636.07J49.082104.0gBL0京1“gSearchProiet和n些indo,Ijelpq虐时自/e)IDrel.t4、IFiProblemsJavadoc图)Dodaratfon里ConsoleS3X%|MbniriinaEd+EXP1Da?占ApplkahanCiVroqmFil&gUavMjMl正一足但丫占此酬甘(201E-Tlm已工就口;口四、实验小结与建议:1、初步理解I/O流的卞S念,掌握其分类,2、掌握文本文件读写、二进制文件读写成都大学信息科学与技术学院制