您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 【精品论文】使用FileInputStream和FileOu
使用FileInputStream和FileOutputStream类将当前目录中的Write1.txt文件复制成Write2.txt文件-报告JAVA2程序设计实用教程之Java的面向对象特征上机报告|上机实验实习报告|计算机上机实习报告|使用FileInputStream和FileOutputStream类将当前目录中的Write1.txt文件复制成Write2.txt文件|如果去掉sleep语句(同时去掉catch(InterruptedExceptione)语句),则运行结果将会是怎样算法:importjava.io.*;publicclassWrite1{publicstaticvoidmain(Stringargs[]){try{System.out.print(Input:);intcount,n=512;bytebuffer[]=newbyte[n];count=System.in.read(buffer);//读取标准输入流FileOutputStreamwf1=newFileOutputStream(Write1.txt);FileOutputStreamwf2=newFileOutputStream(Write2.txt);FileInputStreamrf=newFileInputStream(Write1.txt);wf1.write(buffer,0,count);//写入输出流wf1.close();//关闭输出流System.out.println(SavetoWrite1.txt!);rf.read(buffer,0,count);wf2.write(buffer,0,count);wf2.close();rf.close();System.out.println(copytoWrite2.txt!);}catch(IOExceptionioe){System.out.println(ioe);}catch(Exceptione){System.out.println(e);}}}结果:若图片无法显示请联系站长QQ3249114如果去掉sleep语句(同时去掉catch(InterruptedExceptione)语句),则运行结果将会是怎样?算法:importjava.io.*;publicclassPipedstream{publicstaticvoidmain(Stringargs[]){PipedInputStreamin=newPipedInputStream();PipedOutputStreamout=newPipedOutputStream();try{in.connect(out);}catch(IOExceptionioe){}Sends1=newSend(out,1);Sends2=newSend(out,2);Receiver1=newReceive(in);Receiver2=newReceive(in);s1.start();s2.start();r1.start();r2.start();}}classSendextendsThread//发送线程{PipedOutputStreamout;staticintcount=0;//记录线程个数intk=0;publicSend(PipedOutputStreamout,intk){this.out=out;this.k=k;this.count++;//线程个数加1}publicvoidrun(){System.out.print(\r\nSend+this.k+:+this.getName()+);inti=k;try{while(i10){out.write(i);i+=2;//sleep(1);}if(Send.count==1)//只剩一个线程时{out.close();//关闭输入管道流System.out.println(outclosed!);}elsethis.count--;//线程个数减1}//catch(InterruptedExceptione){}catch(IOExceptione){}}}classReceiveextendsThread//接收线程{PipedInputStreamin;publicReceive(PipedInputStreamin){this.in=in;}publicvoidrun(){System.out.print(\r\nReceive:+this.getName()+);try{inti=in.read();while(i!=-1)//输入流未结束时{System.out.print(i+);i=in.read();//sleep(1);}in.close();//关闭输入管道流}//catch(InterruptedExceptione){}catch(IOExceptione){System.out.println(e);}}}结果:若图片无法显示请联系站长QQ3249114无耻悲鄙下流的网学网总是抄六维论文网的论文,现六维论文网启用新的域名http://www./
本文标题:【精品论文】使用FileInputStream和FileOu
链接地址:https://www.777doc.com/doc-5534 .html