JavaOOP IO 字符流

来源:互联网 发布:linux ttf字体 编辑:程序博客网 时间:2024/04/20 18:41
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");}}

0 0
原创粉丝点击