第7章Java的输入/输出流 H 例73 import java. 10 M public class My Class3 implements Filename Filter i File f public static void main(String argsi File fl=new File("c: jbuilder \myprojects") if(!fl. isDirectoryO Transcript println("Error: +f1+isn't a directory! " else myClass3 m=new MyClass3(f1)
第7章 Java的输入/输出流 例7.3 import java.io.*; public class MyClass3 implements FilenameFilter { File f; public static void main(String args[]){ File f1=new File("c:\\jbuilder3\\myprojects"); if(!f1.isDirectory()) Transcript.println("Error: "+f1+"isn't a directory!"); else{ MyClass3 m=new MyClass3(f1);
第7章Java的输入/输出流 H String dirlist[=fllist(m) for(int 1=0; K<dirList length; 1++) Transcript printIn(dirlistiD public myClass3 (File f, this ff, j public boolean accept(file dir, string name) return name starts With("un")
第7章 Java的输入/输出流 String dirList[]=f1.list(m); for(int i=0;i<dirList.length;i++) Transcript.println(dirList[i]); } } public MyClass3(File f) { this.f=f; } public boolean accept(File dir, String name){ return name.startsWith("un"); } }
H 第7章Java的输亼/输出流 7.22文件IO处理 Byte流(字节流)文件的读取 该类的结构如图7.1所示,我们主要用其中的 FileOutputStream和 Filelnputstream类,它们的父类为 InputStream和 OutputStream。主要的方法有: ● InputStrean nt reado int read(byte budD) int read(byte buf[l, int offset, int length) close
第7章 Java的输入/输出流 7.2.2 文件I/O处理 1.Byte流(字节流)文件的读取 该类的结构如图7.1所示,我们主要用其中的 FileOutputStream和FileInputStream类,它们的父类为 InputStream和OutputStream。主要的方法有: ● InputStream int read() int read(byte buf[]) int read(byte buf[],int offset, int length) close()
第7章Java的输入/输出流 H ● OutputStream int write(int c) int write(byte bufDD) int write(byte buf[l, int offset, int length close 下面给出一个应用实例74
第7章 Java的输入/输出流 ● OutputStream int write(int c) int write(byte buf[]) int write(byte buf[],int offset,int length) close() 下面给出一个应用实例7.4
第7章Java的输入/输出流 H Transcript Win.-OX untitled 1 untitled untitled untitled untitled 图7.5
第7章 Java的输入/输出流 图 7.5