import java.io.Closeable; import java.io.DataInput; import java.io.DataOutput; import java.io.File; import java.io.FileNotFoundException; import java.io.FilterInputStream; import java.io.FilterOutputStream; import java.io.Flushable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.ObjectStreamConstants; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.Reader; import java.io.Serializable; import java.io.Writer; public class IoStream { public static void main(String[] agrs){ /***************** File *****************/ //首先是File类 //public class File implements Serializable, Comparable<File> //File f = new File("_Movie_"); //File f = new File(File.separator);表示当前根目录,为的是Linux下也可以用 //String strFileName = "temp"+File.separator+"test.txt"; //File strF = new File(f,strFileName); /这样也行,别一种构造方法 //f.delete(); 直接删除文件 //f.deleteOnExit(); 程序退出的时候才删除文件 //String[] fileName = f.list(new FilenameFilter(){ //public boolean accept(File dir, String name) { //return name.indexOf(".class")!=-1; //} //});FilenameFilter文件过滤器 /***************** FileInputStream and FileOutputStream *****************/ //FileInputStream fis = new FileInputStream("c:\\1.txt"); // //public class FileInputStream extends InputStream //他的两个构造方法 //public FileInputStream(File file) throws FileNotFoundException //public FileInputStream(String name) throws FileNotFoundException //其它方法 //private native int readBytes(byte b[], int off, int len) throws IOException; //public int read(byte b[]) throws IOException //public native int read() throws IOException //public class FileOutputStream extends OutputStream; //他的两个构造方法 //public FileOutputStream(String name) throws FileNotFoundException //public FileOutputStream(String name, boolean append) throws FileNotFoundException append表示重写,还是在未尾写 //其它方法 //public native void write(int b) throws IOException; //public void write(byte b[]) throws IOException; //public void write(byte b[], int off, int len) throws IOException; /*************** BufferedInputStream and BufferedOutputStream **********************/ //public class BufferedOutputStream extends FilterOutputStream //他的两个构造方法 //public BufferedOutputStream(OutputStream out); //public BufferedOutputStream(OutputStream out, int size); //其它方法 //public synchronized void write(int b) throws IOException; //public synchronized void write(byte b[], int off, int len) throws IOException; //public synchronized void flush() throws IOException; //public class BufferedInputStream extends FilterInputStream //他的构造方法 //public BufferedInputStream(InputStream in) //public BufferedInputStream(InputStream in, int size) //其它方法 //public synchronized int read() throws IOException //public synchronized int read(byte b[], int off, int len)throws IOException /*************** DataOutputStream and DataInputStream **********************/ //public class DataOutputStream extends FilterOutputStream implements DataOutput //构造方法 //public DataOutputStream(OutputStream out) //有很多很多写入基本数据类型的方法 //public class DataInputStream extends FilterInputStream implements DataInput //构造方法 //public DataInputStream(InputStream in) //有很多很多读取基本数据类型的方法 /*************** PipedOutputStream and PipedInputStream **********************/ //public class PipedOutputStream extends OutputStream //构造方法 //public PipedOutputStream(); //public PipedOutputStream(PipedInputStream snk) throws IOException //其它方法 //public synchronized void connect(PipedInputStream snk) throws IOException //public void write(int b) throws IOException //public synchronized int read(byte b[], int off, int len) throws IOException //public class PipedInputStream extends InputStream //构造方法 //public PipedInputStream(PipedOutputStream src) throws IOException //public PipedInputStream(); //其它方法 //public void connect(PipedOutputStream src) throws IOException //public synchronized int read(byte b[], int off, int len) throws IOException //public synchronized int read() throws IOException /************************* Reader and Writer ****************************/ //public abstract class Reader implements Readable, Closeable //public abstract class Writer implements Appendable, Closeable, Flushable /************************* InputStreamReader and OutputStreamWriter ****************************/ //public class InputStreamReader extends Reader //构造方法 //public InputStreamReader(InputStream in)最简单的,字符流与字节流相关连 //其它方法 //public int read(char cbuf[], int offset, int length) throws IOException //public int read() throws IOException //public class OutputStreamWriter extends Writer //构造方法 //public OutputStreamWriter(OutputStream out)最简单的,字符流与字节流相关连 //public void write(int c) throws IOException //public void write(char cbuf[], int off, int len) throws IOException /************************* FileReader and FileWriter ****************************/ //public class FileReader extends InputStreamReader //构造方法 //public FileReader(String fileName) throws FileNotFoundException; //public FileReader(File file) throws FileNotFoundException //读写的方法和InputStreamReader相同 //public class FileWriter extends OutputStreamWriter //构造方法 //public FileWriter(String fileName) throws IOException //public FileWriter(String fileName, boolean append) throws IOException //读写的方法和InputStreamReader相同 /************************* BufferedReader and BufferedWriter ****************************/ //public class BufferedReader extends Reader //构造方法 //public BufferedReader(Reader in) //public BufferedReader(Reader in, int sz) //其它方法 //public String readLine() throws IOException,其它方法略 //public class BufferedWriter extends Writer //构造方法 //public BufferedWriter(Writer out) //public BufferedWriter(Writer out, int sz) //其它方法 //public void newLine() throws IOException 换行 //public void write(String s, int off, int len) throws IOException 写入 //public void write(char cbuf[], int off, int len) throws IOException /************************* ObjectOutputStream and ObjectInputStream ****************************/ //public class ObjectOutputStream extends OutputStream implements ObjectOutput, ObjectStreamConstants //构造方法 //public ObjectOutputStream(OutputStream out) throws IOException //其它方法 //public final void writeObject(Object obj) throws IOException //public class ObjectInputStream extends InputStream implements ObjectInput, ObjectStreamConstants //构造方法 //public ObjectInputStream(InputStream in) throws IOException //其它方法 //public final Object readObject() /************************* PrintStream and PrintWriter ****************************/ //public class PrintStream extends FilterOutputStream //构造方法 //public PrintStream(OutputStream out) //其它方法 //...... //public class PrintWriter extends Writer //构造方法 //很多 //其它方法 //也很多 // System.setIn(InputSteram in); // System.setOut(PrintStream out); // System.setErr(PrintStream err); //改变输入输出的地方 } }