IO总结

来源:互联网 发布:淘宝邮箱注册企业名称 编辑:程序博客网 时间:2024/04/29 11:24

总结:

字节

  InputStream                     OutputStreamFileInputStream               FileOutputStreamBufferedInputStream           BufferedOutputStreamByteArrayInputStrem           ByteArrayOutputStreamDataInputStream               DataOutputStream                PrintStream

字符

Reader                    Writer FileReader         FileWriter BufferedReader     BufferedWriter InputStreamReader      OutputStreamWriter            PrintWriter

int read()int read(byte[] b)int read(byte[] b,int off,int len)int read()int read(char[] ch)int read(char[] ch,int off,int len)BufferedReader--->String readLine()

void write(int b)void write(byte[] b)void write(byte[] b ,int off,int len)void write(int c)void write(char[] ch)void write(char[] ch,int off,int len)void write(String str)void write(String str,int off,int len)BufferedWriter:---> void newLine()void flush()close()

转换流:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));String line = br.readLine();

内存流:长度可变的字节数组

ByteArrayOutputStream baos = new ByteArrayOutputStream();

baos.write();//将数据写入内存 3中

读:1)    byte[] data = baos.toByteArray()2)文本    String str = baos.toString();3)使用内存输入流    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());    byte[] data = new byte[baos.toByteArray().length];    bais.read(data);4)    baos.writeTo(OutputStream)    baos.writeTo(new FileOutputStream("a.txt"));

打印流:

PrintStreamPrintWriter除了继承的write()方法构造方法第二个参数boolean autoFlush 自动刷新。新增    print    println()

数据流:专门用于写和读基本数据类型的

readInt()readBoolean()readUTF()...writeInt()writeBoolean()writeUTF()...         

Object流:

对象输入流ObjectInputStream对象输出流ObjectOutputStream

序列化:

对象---->文件中的数据反序列化:文件中的数据---->对象注意:使用对象流进行操作的时候,必须保证对象是可序列化

创建流步骤:

1 创建自定义类,实现接口,可序列化java.io.Serializable 接口 .该接口中没有任何方法需要实现,标记2 创建对象,使用ObjectOutputStream将对象写入本地(序列化)3 利用ObjectInputStream将对象从本地读取出来(反序列化)注意:属于对象的属性是可以被序列化的本能被序列化1 静态属性  不能被序列化2 transient 透明的修饰的不能序列化

IO
字节 字符
流名称 输入流 输出流 输入流 输出流 功能
4大基类 InputStream OutputStream Reader Writer 抽象类
文件流* FileInputStream FileOutputStream FileReader FileWriter 节点流
System类* System.in System.out
缓存流* BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter 处理流
转换流* InputStreamReader OutputStreamWriter 处理流
打印流 PrintStream PrintWriter
内存流* ByteArrayInputStream ByteArrayOutputStream 节点流
数据流 DataInputStream DataOutputStream 处理流
对象流 ObjectInputStream ObjectOutputStream 处理流 对象序列化和反序列化
随机访问文件 RandomAccessFile类(Object类的子类)

字节    int read()    int read(byte[] b)    int read(byte[] b,int off,int len)字符    int read()    int read(char[] ch)    int read(char[] ch,int off,int len)    String readLine()---->BufferedReader

字节    void write(int b)    void write(byte[] b)    void write(byte[] b,int off,int len)字符    void write(int c)    void write(char[] ch)    void write(char[] ch,int off,int len)    void write(String s)    void write(String s,int off, int len)    void newLine()--->BufferedWriter

数据流:

readXXX()writeXXX()

对象流 :对象是可序列化的 implements java.io.Serializable;

readXXX()writeXXX()readObject()writeObject()

内存流:长度可变的字节数组

ByteArrayOutputStream:byte[] toByteArray()String toString()writeTo(OutputStream os)![IO流汇总](http://img.blog.csdn.net/20151217213248162)        
1 0
原创粉丝点击