Advertisement
iskren_penev

AllCapitals

Mar 20th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class AllCapitals {
  4.     public static void main(String[] args) {
  5.         File path = new File("resources/AllCapitals/lines.txt");
  6.         File finalPath = new File (path + ".tmp");
  7.         finalPath.getParentFile().mkdirs();
  8.         try (BufferedReader bfr = new BufferedReader(new FileReader(path));
  9.              BufferedWriter bw = new BufferedWriter(new FileWriter(finalPath))) {
  10.             String s;
  11.             String full ="";
  12.             while ((s = bfr.readLine()) != null) {
  13.                 s = s.toUpperCase();
  14.                 full += s + "\r\n";
  15.             }
  16.             bw.write(full);
  17.  
  18.         } catch (FileNotFoundException fnf) {
  19.             System.out.println("File not found!");
  20.         } catch (IOException ioe) {
  21.             System.out.println("File not found!");
  22.         }
  23.         if (path.delete()) {
  24.             finalPath.renameTo(path);
  25.         }
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement