javaOOp 字符流读取文件

    xiaoxiao2021-04-18  72

    package cn.happy3; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Day01 { /** * 1.字符流读取文件 * @throws IOException */ public static void main(String[] args) throws IOException { FileReader reader=new FileReader("E:/S2226.txt"); char[] chars=new char[1024]; int data; while((data=reader.read(chars))!=-1){ String temp=new String(chars,0,data); System.out.println(temp); } reader.close(); } } package cn.happy3; import java.io.FileWriter; import java.io.IOException; public class Day02 { /** * FileWriter * @throws IOException */ public static void main(String[] args) throws IOException { FileWriter writer=new FileWriter("E:/S2226.txt"); String words="呵呵"; writer.write(words); writer.close(); } }
    转载请注明原文地址: https://ju.6miu.com/read-675538.html

    最新回复(0)