欢迎来到天天文库
浏览记录
ID:55602725
大小:30.50 KB
页数:7页
时间:2020-05-20
《马俊-兰大ava实验-05.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、//ByteStreamTest.javaimportjava.io.*;publicclassByteStreamTest{publicstaticvoidmain(String[]args)throwsIOException{FileOutputStreamout1=newFileOutputStream("data.txt");BufferedOutputStreamout2=newBufferedOutputStream(out1);DataOutputStreamout=newDataOutput
2、Stream(out2);out.writeByte(-12);out.writeLong(12);out.writeChar('A');out.writeUTF("中国");out.close();InputStreamin1=newFileInputStream("data.txt");BufferedInputStreamin2=newBufferedInputStream(in1);DataInputStreamin=newDataInputStream(in2);System.out.printl
3、n(in.readByte());System.out.println(in.readLong());System.out.println(in.readChar());System.out.println(in.readUTF());in.close();}}//copy.javaimportjava.io.*;publicclasscopy{publicstaticvoidmain(Stringargs[]){Fileno2=newFile("no2.txt");Fileno1=newFile("no1
4、.txt");try{FileReaderin=newFileReader(no1);BufferedReaderin1=newBufferedReader(in);FileWriterout=newFileWriter(no2);BufferedWriterout1=newBufferedWriter(out);Stringdata;intn=1;while((data=in1.readLine())!=null){out1.write(n+":"+data);out1.newLine();n++;}ou
5、t1.flush();out1.close();in1.close();}catch(Exceptione){System.out.println("出现异常!");}}}//FileConvert.javaimportjava.io.*;publicclassFileConvert{publicvoidreadFile(StringfileName)throwsIOException{readFile(fileName,null);}publicvoidreadFile(StringfileName,St
6、ringcharsetName)throwsIOException{InputStreamin=newFileInputStream(fileName);InputStreamReaderreader;if(charsetName==null){reader=newInputStreamReader(in);}else{reader=newInputStreamReader(in,charsetName);}BufferedReaderbr=newBufferedReader(reader);Stringd
7、ata;while((data=br.readLine())!=null){System.out.println(data);}br.close();}publicvoidcopyFile(Stringfrom,StringcharsetFrom,Stringto,StringcharsetTo)throwsIOException{InputStreamin=newFileInputStream(from);InputStreamReaderreader;if(charsetFrom==null){read
8、er=newInputStreamReader(in);}else{reader=newInputStreamReader(in,charsetFrom);}BufferedReaderbr=newBufferedReader(reader);OutputStreamout=newFileOutputStream(to);OutputStreamWriterwriter=newOutputStreamWriter
此文档下载收益归作者所有