码迷,mamicode.com
首页 > 编程语言 > 详细

Java学习日记 I/O

时间:2015-10-27 21:43:10      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

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

 

Java学习日记 I/O

标签:

原文地址:http://www.cnblogs.com/youilika/p/4915278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!