二进制文件读写:
FileOutputStream
FileInputStream
DataOutputStream
DataInputStream
BufferedOutputStream
BufferedInputStream
字符流的读写
Reader
Writer
FileReader
FileWriter
BufferedReader
BufferedWriter
PrintWriter
PrintStream
InputStreamReader
OutputStreamWriter
关于read;
1.FileInputStream :
read()
一个字节一个字节的读取,当读取到字节时就返回该字节的int型数值
read(byte[] b)
先规定一个byte数组长度,将这个流中的字节缓冲到数组b中,则返回读取到的字节个数,到未尾时返回-1
源码:
public int read(byte b[]) throws IOException {
return readBytes(b, 0, b.length);
}
read(byte[] b,int off,int len)
b - 读取字节数组数据,off - 开始在目标数组b的偏移,len - 要读取的最大字节数
返回int读取到的字节数
2.DataInputStream
打字好累啊,我截屏
注意:
readUTF(),是从输入流中读取UTF-8编码的数据,并以String字符串的形式返回。
readFully();无返回值;要求读出的字节长度与byte[]的长度相同
readBoolean();读取到的字节不为零返回true,如果字节是零方法返回false。
readChar();读取两个字节,返回读取到char类型的值;
3.FileReader
read(); 读取单个字符。返回作为整数读取的字符,如果已达到流末尾,则返回 -1。
read(char []cbuf);将字符读入数组。返回读取的字符数。如果已经到达尾部,则返回-1。
4.BufferedReader
readLine();返回读取到的字符串;
以上只是我的理解,内容只做参考,欢迎提出问题,一起进步哈~~!!^.^