您的位置:首页 > 编程语言 > Java开发

Java学习日记 I/O

2015-10-27 19:15 405 查看
File类
1.String[] list() 返回一个目录下文件和文件夹路径的字符串数组
2.File[] listFiles() 以File类对象数组,返回目录下的所有文件和文件夹
3.isDirectory()判断是否是目录

OutputStream抽象类
1.直接子类FileOutputStream(字节流)
构造方法
(1)FileOutputStream(File file)
(2)FileOutputStream(File file, boolean append)
append为true代表追加
基本方法
void write(int b)将指定字节写入此文件输出流。
void write(byte[] b)将 b.length 个字节从指定 byte 数组写入此文件输出流中。
void write(byte[] b, int off, int len)将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此文件输

出流。
void close()关闭此文件输出流并释放与此流有关的所有系统资源。

InputStream抽象类
1.直接子类FileInputStream(字节流)
构造方法
FileInputStream(File file)
FileInputStream(String name)
基本方法
void close()
int read() Reads a byte of data from this input stream.
int read(byte[] b) Reads up to b.length bytes of data from this input stream into an array of bytes.
int read(byte[] b, int off, int len) Reads up to len bytes of data from this input stream into an

array of bytes.
(read throws IOException)

Reader抽象类,字符流,可以读取汉字等两个字节的字符
1.子类
FileReader extends InputStreamReader extends Reader
FileReader(File file)
FileReader(String fileName)
2.方法
public int read()throws IOException //注意:返回的是int值
public void close()throws IOException

Writer抽象类,字符流
1.子类
FileWriter
构造方法
FileWriter(File file)
FileWriter(File file, boolean append)
基本方法
public void write(char[] cbuf) throws IOException
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: