黑马程序员_IO流初步

来源:互联网 发布:火箭队 机械 知乎 编辑:程序博客网 时间:2024/04/29 17:37
------- android培训、java培训、期待与您交流! ----------

Stream
 字节流字符流输入流InputStreamReader输出流OutputStreamWriter
按数据流方向不同分为输入流和输出流。
按处理数据单位不同分为字节流和字符流。
按功能不同分为节点流和处理流。

InputStream拥有方法:


int read () throws IOException//读一个字节
int read (byte[] buffer) throws IOException//将字节读到byte数组中
int read (byte[] buffer, int offset, int length) throws IOException//将字节读到byte数组中的offset到length长度中
void close () throws IOException//关闭流
long skip (long n) throws IOException//跳过n个字节不读


OutputStream拥有的方法:

void write (int b) throws IOException//写到b中。
void write (byte[] b) throws IOException//写到byte数组中
void write (byte[] b, int off ,int len ) throwsIOException//。。。
void close () throws IOException
void flush () throws IOException//将流中的数据刷新出去

Reader的基本方法:

int read () throws IOException
int read (char[] cbuf) throws IOException//读几个字符到char[]中
int read (char[] cbuf ,int offser, int length) throws IOException
void close () throws IOEception
long skip (long n) throws IOException

Writer的基本方法

void write (int c) throws IOException
void write (char[] cbuf) throws IOException
void write (char[] cbuf, int offset ,int length) throws IOException
void write (String string) throws IOException
void write (String string  , int offset , int length) throws IOException
void close () throws IOException
void flush () throws IOException

节点流:

继承Writer、Outputstream、Reader、InputStream的方法


数据处理流


BufferedReader 这个readline()方法不会读出换行符,
BufferedWriter 实例 在writeline()这个方法写下readline()方法时,记得要加boject.newLine()



数据转换流
OutputStreamWriter
InputStreamReader 实例



数据流

DataOutputStream
DataInPutStream

read
 write
使用方法:


Print流




Object流


Serializable      可以被序列化的标记接口
transient 透明的 ,在序列化的时候将会透明,无法显示
externalizable   自己控制序列化过程接口,是Serializable的子接口


了解到能够传入子类对象,则该子类对象肯定实现了这个抽象方法,就可以用子类对象来实现该方法,写法如上图

------- android培训、java培训、期待与您交流! ----------
0 0
原创粉丝点击