Didart

Sum Bytes

Jan 26th, 2023 (edited)
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package StreamsFilesAndDirectories4;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class SumBytes {
  10.     public static void main(String[] args) throws IOException {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         String pathToFile = "C:\\Users\\User\\Desktop\\Java Advanced - 10.01.23 - 13.09.22\\src\\StreamsFilesAndDirectories4\\04. Java-Advanced-Files-and-Streams-Exercises-Resources\\input.txt";
  14.         List<String> allLines = Files.readAllLines(Path.of(pathToFile));
  15.  
  16.         long sum = 0;
  17.         for (String line : allLines) {
  18.             for (char symbol : line.toCharArray()) {
  19.                 sum += symbol;
  20.             }
  21.         }
  22.         System.out.println(sum);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment