Advertisement
desislava_topuzakova

3. ALL CAPITALS!

Jan 22nd, 2022
568
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package StreamsFilesDirectories_Exercise;
  2.  
  3. import java.io.*;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.util.List;
  7. import java.util.Locale;
  8.  
  9. public class AllCapitals_03 {
  10.     public static void main(String[] args) throws IOException {
  11.         String path = "C:\\Users\\I353529\\Desktop\\04. Java-Advanced-Files-and-Streams-Exercises-Resources\\input.txt";
  12.         BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
  13.         //1. прочитаме файла
  14.         //2. обхождаме всеки ред -> правим всички букви главни -> записваме реда в нов файл
  15.  
  16.         //начин 1
  17.         /*List<String> allLines = Files.readAllLines(Path.of(path));
  18.         for (String line : allLines) {
  19.             bw.write(line.toUpperCase());
  20.             bw.newLine();
  21.         }
  22.         bw.close();*/
  23.  
  24.         BufferedReader reader = new BufferedReader(new FileReader(path));
  25.         String line = reader.readLine();
  26.         while (line != null) {
  27.             writer.write(line.toUpperCase());
  28.             writer.newLine();
  29.  
  30.             line = reader.readLine();
  31.         }
  32.         writer.close();
  33.     }
  34. }
  35.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement