1 需求
2 接口
Class Reader
java.lang.Object
java.io.Reader
- Field Detail
- protected Object lock
- Constructor Detail
- protected Reader()
- protected Reader(Object lock)
- Method Detail
- public abstract void close() throws IOException
- public int read() throws IOException
- public int read(char[] cbuf) throws IOException
- public abstract int read(char[] cbuf, int off, int len) throws IOException
- public int read(CharBuffer target) throws IOException
Class Writer
java.lang.Object
java.io.Writer
- Field Detail
- protected Object lock
- Constructor Detail
- protected Writer()
- protected Writer(Object lock)
- Method Detail
- public Writer append(char c) throws IOException
- public Writer append(CharSequence csq) throws IOException
- public Writer append(CharSequence csq, int start, int end) throws IOException
- public abstract void close() throws IOException
- public abstract void flush() throws IOException
- public void write(char[] cbuf) throws IOException
- public abstract void write(char[] cbuf, int off, int len) throws IOException
- public void write(int c) throws IOException
- public void write(String str) throws IOException
- public void write(String str, int off, int len) throws IOException
3 示例代码
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
// 字符流 示例
Reader reader = new FileReader("C:\test.txt");
int i = 0;
while ((i = reader.read()) != -1) {
System.out.println(i);
}
reader.close();
System.out.println("******* 分割线 ******");
//字节流 示例
InputStream inputStream = new FileInputStream("C:\test.txt");
int j = 0;
while ((j = inputStream.read()) != -1) {
System.out.println(j);
}
inputStream.close();
}
}
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
Writer writer = new FileWriter("C:\test.txt");
writer.write("中国");
writer.close();
}
}
4 参考资料



