Use a BufferedReader and a BufferedWriter to copy a text file, inverting the case of letters in the process : BufferedWriter « File « Java Tutorial






import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class Main {
  public static void main(String[] argv) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("in.txt"));
    BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt"));
    int i;
    do {
      i = br.read();
      if (i != -1) {
        if (Character.isLowerCase((char) i))
          bw.write(Character.toUpperCase((char) i));
        else if (Character.isUpperCase((char) i))
          bw.write(Character.toLowerCase((char) i));
        else
          bw.write((char) i);
      }
    } while (i != -1);
    br.close();
    bw.close();
  }
}








11.36.BufferedWriter
11.36.1.BufferedWriter
11.36.2.Create BufferedWriter from FileWriter
11.36.3.Read Input From User and Write to File
11.36.4.Write to file using a BufferedWriter
11.36.5.Use a BufferedReader and a BufferedWriter to copy a text file, inverting the case of letters in the process
11.36.6.Writing to a File: If the file does not exist, it is automatically created.
11.36.7.Appending to a File
11.36.8.Nested creation of FileWriter, BufferedWriter and PrintWriter