文件读写3

    xiaoxiao2021-03-25  159

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Filedemo3 { public static void main(String[] args) {

    try {

    //字节流读写文件

    FileReader fr = new FileReader("test.txt"); BufferedReader  br = new BufferedReader(fr); FileWriter fw = new FileWriter("testw.txt"); BufferedWriter bw = new BufferedWriter(fw); String line; while ((line = br.readLine()) != null) { bw.write(line + "\n"); } bw.flush();//强制缓冲区输出 bw.close(); fw.close(); br.close(); fr.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
    转载请注明原文地址: https://ju.6miu.com/read-1473.html

    最新回复(0)