Advertisement
Jakzon123

java edit file contents to uppercase

Nov 13th, 2022
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class FileIO {
  4.     public static void main (String[] args) throws IOException {
  5.         // Create input stream
  6.         FileReader fr = new FileReader("test.txt");
  7.         BufferedReader in = new BufferedReader(fr);
  8.  
  9.         // Create output stream
  10.         FileWriter fw = new FileWriter("out.txt");
  11.         BufferedWriter out = new BufferedWriter(fw);
  12.  
  13.         boolean eof = false;
  14.         int inChar;
  15.         do {
  16.             inChar = in.read();
  17.             if (inChar != -1) {
  18.                 char outChar = Character.toUpperCase((char) inChar);
  19.                 out.write(outChar);
  20.             } else
  21.                 eof = true;
  22.             } while (!eof);
  23.                 in.close();
  24.                 out.close();
  25.         }      
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement