Advertisement
deyanmalinov

5. Write Every Third Line

Apr 8th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.io.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         String inputPath = "D:\\Coding\\Java\\Softuni\\Java Advanced - January 2019" +
  8.                 "\\04. Java-Advanced-Fiels-and-Directories-Lab\\04. Java-Advanced-" +
  9.                 "Files-and-Streams-Lab-Resources\\input.txt";
  10.         String outputPath = "D:\\Coding\\Java\\Softuni\\Java Advanced - January 2019" +
  11.                 "\\04. Java-Advanced-Fiels-and-Directories-Lab\\04. Java-Advanced-" +
  12.                 "Files-and-Streams-Lab-Resources\\output.txt";
  13.  
  14.         try (BufferedReader reader = new BufferedReader(new FileReader(inputPath));
  15.              PrintWriter writer = new PrintWriter(new FileWriter(outputPath))){
  16.             int coutner = 1;
  17.             String line = null;
  18.             line = reader.readLine();
  19.             while (line != null){
  20.                 if (coutner % 3 ==0){
  21.                     writer.println(line);
  22.                 }
  23.                 coutner++;
  24.                 line=reader.readLine();
  25.             }
  26.         } catch (IOException e) {
  27.             e.printStackTrace();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement