Java BufferedWriter copy text file and invert letter case

Description

Java BufferedWriter copy text file and invert letter case



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("Main.java"));
    BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt"));
    int i;/*  w ww .j a  v a2 s. com*/
    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();
    System.out.println("done");
  }
}



PreviousNext

Related