package cn.hello.io;
/**
* 字符流 读取
*/
import java.io.FileNotFoundException;
import java.io.FileReader;
public class Test3 {
public static void main(String[] args) throws Exception {
FileReader reader=new FileReader("e:/s2226.txt");
char[] chars=new char[1024];
int data;
while ((data=reader.read(chars))!=-1) {
String str=new String(chars,0,data);
System.out.println(str);
}
reader.close();
}
}
package cn.hello.io;
/**
* 字符流 写入
*/
import java.io.FileWriter;
import java.io.IOException;
public class Test4 {
public static void main(String[] args) throws Exception {
FileWriter writer=new FileWriter("e:/s2226.txt");
String str="你好吗";
writer.write(str);
writer.close();
System.out.println("ok");
}
}
08-16
08-16