文件/O流类的构造函数 通过输入输出文件创建FileInputStream, FileOutputStream,FileReader,.和FileWriter实例: FileInputStream infile new FileInputStream("in.dat"); FileOutputStream outfile new FileOutputStream(out.dat); FileReader infile new FileReader("in.dat); FileWriter outfile new FileWriter(out.dat); ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. 文件I/O流类的构造函数 通过输入输出文件创建 FileInputStream, FileOutputStream, FileReader, 和FileWriter 实例: FileInputStream infile = new FileInputStream("in.dat"); FileOutputStream outfile = new FileOutputStream("out.dat"); FileReader infile = new FileReader("in.dat"); FileWriter outfile = new FileWriter("out.dat");
范例:处理外部文件 FileInputStream fis args[0] 程序 args[1] FileOutputStream fos CopyFileUsingByteStream ©2006计算机系杨厚群 All rights&lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. 范例:处理外部文件 FileInputStream fis 程序 args[1] args[0] FileOutputStream fos CopyFileUsingByteStream
数据流 数据流(DataInputStream和 DataOutputStream),以与机器无关的方式读取 和写入Java的基本数据类型数据,即可以在一 台机器上写一个数据文件,到另一台不同操作 系统或不同文件结构的机器上读取该文件 ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. 数据流 数据流(DataInputStream 和 DataOutputStream)以与机器无关的方式读取 和写入Java的基本数据类型数据,即可以在一 台机器上写一个数据文件,到另一台不同操作 系统或不同文件结构的机器上读取该文件
DataInputStream类的方法 int readByte()throws IOException int readShort()throws IOException int readInt()throws IOException int readLong()throws IOException float readFloat()throws IOException double readDouble()throws IOException char readChar()throws IOException boolean readBoolean()throws IOException String readUTF()throws IOException ©2006计算机系杨厚群 All rights lefts reserved
©2006 计算机系 杨厚群 All rights & lefts reserved. DataInputStream类 的方法 int readByte() throws IOException int readShort() throws IOException int readInt() throws IOException int readLong() throws IOException float readFloat() throws IOException double readDouble() throws IOException char readChar() throws IOException boolean readBoolean() throws IOException String readUTF() throws IOException