JavaOOP字符流

    xiaoxiao2021-04-19  78

    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"); } }
    转载请注明原文地址: https://ju.6miu.com/read-675716.html

    最新回复(0)