- 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
您可能关注的文档
最近下载
- 施工现场各类设备机械安全监理实施细则(参考).doc VIP
- 华东交通大学2015-2016第一学期电牵专业《电机与拖动》期末A卷.doc VIP
- 储气罐专业定期检查表.docx VIP
- JB_T 14788-2024《连续延伸带式输送机》.pdf VIP
- GB 265-1988 运动黏度.pdf
- 山东省青岛市胶州市2024-2025学年七年级上学期期末历史试题(含答案).pdf VIP
- 基于概念整合理论研究母语对二语写作的影响-外国语言学及应用语言学专业论文.docx VIP
- 中国旅游地理第四章旅游区划.ppt VIP
- 《陆上风力发电机组钢混塔架施工关键材料技术规程》.pdf VIP
- 2025年AI图像识别服务合同协议合同.docx VIP
原创力文档

文档评论(0)