文档详情

第9章—文件输入输出.ppt

发布:2017-04-05约2.33万字共50页下载文档
文本预览下载声明
Java语言程序设计 杨 献 峰 yxf110@hist.edu.cn Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. Java I/O操作 概念 Java I/O类 Java I/O操作 标准输入/输出 文件读写操作 目录管理 随机访问文件 文件属性 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 概念 I/O来源 控制台(console, 如DOS窗口)?打印/读入 文件(file)?读/写 网络接口(TCP/UDP端口)?读/写 针对数据的读写 以流(stream)的方式对数据进行操作 流的重要特性 顺序读/写 sequentially Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 概念 读/写流的一般流程 读(Reading) open a stream //打开读出流 while more information //判断 read information //读 close the stream //关闭流 写(Writing) open a stream //打开写入流 while more information //判断 write information //写 close the stream //关闭流 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 概念 两种流的定义(读取信息的基本数据单位) 字节流(byte stream): 一个字节(8-bit)一个字节读/写 字符流(character stream):一个字符一个字符读/写(具有特定字符编码的数据) j a v a 语 言 6A 61 76 61 D3 EF D1 D4 以字节流的方式读: 读8次,8个字节 以字符流的方式读: 读6次,6个字符 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. Java I/O操作 概念 Java I/O类 Java I/O操作 标准输入/输出 文件读写操作 目录管理 随机访问文件 文件属性 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. Java I/O类 字节流的读/写操作(来自JDK1.0) java.io.InputStream (抽象类) public abstract int read() public int read(byte b[]) public int read(byte b[], int offset, int length) 到达流的终点,无数据读出则返回-1 java.io.OutputStream (抽象类) public abstract void write(int b) public void write(byte b[]) public void write(byte b[], int offset, int length) 所有的读/写函数都抛出java.io.IOException Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. Java I/O类 字符流的读/写操作(来自JDK1.1) java.io.Read
显示全部
相似文档