欢迎来到天天文库
浏览记录
ID:49464477
大小:93.50 KB
页数:21页
时间:2020-02-05
《JAVA输入输出流.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第9讲输入/输出流9.1数据流基本概念(1)数据流(stream)是指一组有顺序的、有起点和终点的字节集合,是对输入输出的总称(或抽象)。数据流完成从键盘接收数据、读写文件以及打印等数据传输操作。图9.1输入流与输出流9.1数据流基本概念(2)标准输入system.in,intread()方法从键盘接收一个字节的数据,返回值是该字符的ASCII码;intread(byte[]buf)方法从键盘接收多个字节的数据,保存至buf,返回值是接收字节数据的个数,非ASCII码.标准输出system.out,print()和println()方法向屏幕输出,参数可以是Ja
2、va的任意基本类型。9.1数据流基本概念(3)importjava.io.*;publicclassInput1{publicstaticvoidmain(Stringargs[])throwsIOException{System.out.println("Input:");bytebuffer[]=newbyte[512];//输入缓冲区intcount=System.in.read(buffer);//读取标准输入流System.out.println("Output:");for(inti=0;i3、m.out.print(""+buffer[i]);}System.out.println();for(inti=0;i4、入流的超类它是抽象类,子类才能实例化Writer字符输出流的超类它是抽象类,子类才能实例化以下两个类是单独与文件相关的类,与上述流类不同File文件类非抽象类RandomAccessFile随机访问文件类非抽象类9.2字节流字节输入流InputStream类为所有面向字节的输入流的超类。9.2字节流(2)字节输出流OutputStream类为所有面向字节的输出流的超类。9.2InputStream类提供的方法三个基本的read方法:intread()intread(byte[]buffer)intread(byte[]buffer,intoffset,intle5、ngth)其它方法:voidclose()intavailable()skip(longn)booleanmarkSupported()voidmark(intreadlimit)voidreset()9.2OutputStream类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(byte[]buffer)voidwrite(byte[]buffer,intoffset,intlength)其它方法voidclose()voidflush()9.3字符流字符输入流Reader类为所有面向字符的输入流的超类。ReaderBuf6、feredReaderStringReaderCharArrayReaderInputStreamReaderPipedReaderFilterReaderFileReaderPushbackReaderLineNumberReader9.3字符流(2)字符输出流Writer类为所有面向字符的输出流的超类。WriterBufferedWriterStringWriterCharArrayWriterPipedWriterOutputStreamWriterPrintWriterFilterWriterFileWriter9.3Reader类提供的方法三个基本的r7、ead方法:intread()intread(char[]cbuf)intread(char[]cbuf,intoffset,intlength)其它方法voidclose()booleanready()skip(longn)booleanmarkSupported()voidmark(intreadAheadLimit)voidreset()9.3Writer类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(char[]cbuf)voidwrite(char[]cbuf,intoffset,intlength)voidwr8、ite(Stringst
3、m.out.print(""+buffer[i]);}System.out.println();for(inti=0;i4、入流的超类它是抽象类,子类才能实例化Writer字符输出流的超类它是抽象类,子类才能实例化以下两个类是单独与文件相关的类,与上述流类不同File文件类非抽象类RandomAccessFile随机访问文件类非抽象类9.2字节流字节输入流InputStream类为所有面向字节的输入流的超类。9.2字节流(2)字节输出流OutputStream类为所有面向字节的输出流的超类。9.2InputStream类提供的方法三个基本的read方法:intread()intread(byte[]buffer)intread(byte[]buffer,intoffset,intle5、ngth)其它方法:voidclose()intavailable()skip(longn)booleanmarkSupported()voidmark(intreadlimit)voidreset()9.2OutputStream类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(byte[]buffer)voidwrite(byte[]buffer,intoffset,intlength)其它方法voidclose()voidflush()9.3字符流字符输入流Reader类为所有面向字符的输入流的超类。ReaderBuf6、feredReaderStringReaderCharArrayReaderInputStreamReaderPipedReaderFilterReaderFileReaderPushbackReaderLineNumberReader9.3字符流(2)字符输出流Writer类为所有面向字符的输出流的超类。WriterBufferedWriterStringWriterCharArrayWriterPipedWriterOutputStreamWriterPrintWriterFilterWriterFileWriter9.3Reader类提供的方法三个基本的r7、ead方法:intread()intread(char[]cbuf)intread(char[]cbuf,intoffset,intlength)其它方法voidclose()booleanready()skip(longn)booleanmarkSupported()voidmark(intreadAheadLimit)voidreset()9.3Writer类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(char[]cbuf)voidwrite(char[]cbuf,intoffset,intlength)voidwr8、ite(Stringst
4、入流的超类它是抽象类,子类才能实例化Writer字符输出流的超类它是抽象类,子类才能实例化以下两个类是单独与文件相关的类,与上述流类不同File文件类非抽象类RandomAccessFile随机访问文件类非抽象类9.2字节流字节输入流InputStream类为所有面向字节的输入流的超类。9.2字节流(2)字节输出流OutputStream类为所有面向字节的输出流的超类。9.2InputStream类提供的方法三个基本的read方法:intread()intread(byte[]buffer)intread(byte[]buffer,intoffset,intle
5、ngth)其它方法:voidclose()intavailable()skip(longn)booleanmarkSupported()voidmark(intreadlimit)voidreset()9.2OutputStream类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(byte[]buffer)voidwrite(byte[]buffer,intoffset,intlength)其它方法voidclose()voidflush()9.3字符流字符输入流Reader类为所有面向字符的输入流的超类。ReaderBuf
6、feredReaderStringReaderCharArrayReaderInputStreamReaderPipedReaderFilterReaderFileReaderPushbackReaderLineNumberReader9.3字符流(2)字符输出流Writer类为所有面向字符的输出流的超类。WriterBufferedWriterStringWriterCharArrayWriterPipedWriterOutputStreamWriterPrintWriterFilterWriterFileWriter9.3Reader类提供的方法三个基本的r
7、ead方法:intread()intread(char[]cbuf)intread(char[]cbuf,intoffset,intlength)其它方法voidclose()booleanready()skip(longn)booleanmarkSupported()voidmark(intreadAheadLimit)voidreset()9.3Writer类提供的方法三个基本的write方法:voidwrite(intc)voidwrite(char[]cbuf)voidwrite(char[]cbuf,intoffset,intlength)voidwr
8、ite(Stringst
此文档下载收益归作者所有