关于流

来源:互联网 发布:dr3插件mac安装 编辑:程序博客网 时间:2024/04/28 08:52

流!一般的书,看不懂!
流!流?水!气!钱!   流动。
搞钱币的人,我们泉友。
计算机中也有流!
数据!  数据:
1、字节型的数据 byte   8
2、字符型的数据 char   16

流按照介质:1、字节流    2、字符流
流按照汇源、汇聚分:
你们的父母看了一个片子:《话说长江》 解说:赵忠祥。
从喜马拉雅山----->上海
     汇源   ----->汇聚


流也有汇源和汇聚。
以  内存 为中心。

你是读者。Reader 输入
    作者。Writer 输出


以电脑为中心。
谁是输入设备? 键盘、鼠标、话筒、摄像头等
    输出设备?显示器,音箱,打印机。。。


 内存和硬盘的区别。


如果把数据读到内存中。输入流
如果把数据从内存中,读出并写入到硬盘。输出流

如果把字节数据读到内存中。字节输入流。
如果把字节数据从内存中,读出并写入到硬盘。字节输出流

如果把字符数据读到内存中。字符输入流。
如果把字符数据从内存中,读出并写入到硬盘。字符输出流


流的划分:
按照介质分:
1、字节流
2、字符流

按照汇源汇聚:
1、输入流
2、输出流


1、字节输入流:InputStream
2、字节输出流: OutputStream
3、字符输入流: Reader
4、字符输出流: Writer

字节流最重要,因为他也可以操纵字符流。

Input/Ouput

 I/O 流
一、字节输入流:InputStream
0、包,是否导入

1、定义:public abstract class InputStream
    不能创建对象。
2、公有方法:
    public abstract int read() throws IOException;
    public int read(byte b[]) throws IOException
    public int read(byte b[], int off, int len) throws IOException
   public int available() throws IOException 有效字节数
   public void close() throws IOException

 

 


二、OutputStream:字节输出流
0、package java.io;
1、public abstract class OutputStream
2、方法:
public abstract void write(int b) throws IOException;
public void write(byte b[]) throws IOException
 public void write(byte b[], int off, int len) throws IOException

 public void flush() throws IOException 清缓存!
public void close() throws IOException


三、Reader字符输入流
0、io
1、public abstract class Reader 
2、  public int read() throws IOException 
      public int read(char cbuf[]) throws IOException
 abstract public int read(char cbuf[], int off, int len) throws IOException;

abstract public void close() throws IOException;

四、Writer字符输出流
0、
1、public abstract class Writer
2、
*public void write(int c) throws IOException
*public void write(char cbuf[]) throws IOException
*abstract public void write(char cbuf[], int off, int len) throws IOException;
*public void write(String str) throws IOException
*public void write(String str, int off, int len) throws IOException
*abstract public void flush() throws IOException;
*abstract public void close() throws IOException;

 

问题:
流按照介质分:字符流和字节流
流按照会员汇聚分:输入流和输出流

列举你知道的字符流:
字符输入流:Reader
字符输出流:Writer

列举你知道的字节流:
字节输入流:InputStream
字节输出流:OutputStream

 

Reader类有啥方法?
答:public abstract int read()throws IOException
    public int read(char c[])throws IOException
    public int read(Char c[] ,int s,int ss)throws     IOException
    public void close()throws IOException;

 

Writer类有啥方法?
 public int write(int c)throws IOException;
 public int write(char c[])throws IOException;
 public int write(String s)throws IOException;
 public void close()throws IOException;

InputStream类有啥方法?
答:
public abstract int read()throws IOExcetion
public  int read(byte b[] )   throws IOExcetion
public int read(byte b[] ,int s,int ss)throws IOExcetion
public int available()throws IOExcetion
public void flush()throws IOExcetion
public void close()throws IOExcetion


四个流:四个抽象类,他们是所有流的父类!

在学习流之前,必须首先学File?

五、File
1、public class File implements  Serializable, Comparable
2、构造器
public File(String pathname)
public File(URI uri)
3、常用的公有方法。

* public boolean mkdir();//创建目录,如果返回true成功,否则,失败。 只创建一个文件夹,如果父子文件夹一起创建的画,父文件夹必须先存在。才能创建子,否则失败。
* public boolean mkdirs();、、父子文件夹一起创建。

* public boolean delete()//删除,如果成功返回true


有一个面试题:File类只操纵文件夹(  错! )

* boolean canRead()   可读吗?  如果返回true,则该文件可
读。
* boolean canWrite()  可写吗?

0 0