← Back to feed
Renewal·서른의 생활코딩

ex7) java.io.* - Character Stream

NS
normalstory
cover image

// Character stream file I/O example
// Uses FileReader to read characters from a file
// and FileWriter to write characters to a file

import java.io.*;

public class CharStreamExample {
  public static void main(String[] args) {
    try {
      FileReader fr = new FileReader("input.txt");
      FileWriter fw = new FileWriter("output.txt");
      int ch;
      while((ch = fr.read()) != -1) {
        fw.write(ch);
      }
      fr.close();
      fw.close();
    } catch(IOException e) {
      e.printStackTrace();
    }
  }
}

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.