Writer使用示例
package com.io.reader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.Test;
public class WriterTest {
@Test
public void test01() throws IOException {
File file = new File("b.txt");
FileWriter fw = new FileWriter(file);
fw.write("大家好!");
fw.close();
}
}
Reader的使用
package com.io.reader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.junit.Test;
public class ReaderTest {
@Test
public void test05() throws IOException {
FileReader fr = new FileReader(new File("a.txt"));
char[] cbuf = new char[4];
int len;
while ((len = fr.read(cbuf)) != -1) {
String str = new String(cbuf, 0, len)