输入输出数据流(用).pptVIP

  • 3
  • 0
  • 约2.15千字
  • 约 40页
  • 2017-06-24 发布于湖北
  • 举报
输入输出数据流(用)

第10章 输入输出数据流;流(Stream)的概念;流的概念;流的分类;流的分类(续);字节流的层次结构;字符流(读写器)的类层次结构;InputStream 类的常用方法;OutputStream的常用方法;标准输入输出流和错误流;标准输入 System.in;流的使用过程;例:使用System.in实现键盘数据输入;学习任务:;从文件读数据:FileInputStream;例:读出一个文本文件的内容并显示;向文件写数据:FileOutputStream;例题:使用FileOutputStream实现文件复制。;学习任务:;BufferedInputStream;BufferedOutputStream;输入/输出流的套接;流的套接举例: FileInputStream套接BufferedInputStream;? 属过滤流。能按java的基本数据类型读写流中的数据: DataInputStream方法 byte readByte( ) boolean readBoolean( ) long readLong( ) char readChar( ) double readDouble( ) float readFloat( ) short readshort( ) int readInt( ) String readUTF( )//读取以UTF格式保存的字符串 DataOutputStream 方法 void writeByte(byte) void writeBoolean(boolean) void writeLong( long ) void writeChar(char) void writeDouble(double) void writeFloat( float) void writeshort(short) void writeInt ( int) void writeBytes(String) void writeChars(String ) void WriteUTF(String str)//将字符串以UTF格式写出;过滤流示例;过滤流示例; for (int i = 0; i prices.length; i ++) { out.writeDouble(prices[i]); out.writeChar(\t); out.writeInt(units[i]); out.writeChar(\t); out.writeUTF(descs[i]); out.writeChar(\n); } out.close(); // read it in again DataInputStream in = new DataInputStream(new FileInputStream(invoice1.txt)); double price; int unit; String desc; double total = 0.0; ; for (int i = 0; i prices.length; i ++) { price = in.readDouble(); in.readChar(); // 读入tab键 unit = in.readInt(); in.readChar(); //读入tab键 desc = in.readUTF(); in.readChar(); //读入tab键 System.out.println(Youve ordered + unit + units of + desc + at $ + price); total = total + unit * price; } System.out.println(For a TOTAL of: $ + total

文档评论(0)

1亿VIP精品文档

相关文档