Advertisement
n_stefanov

Ex8_SumNumsFromTextFile

May 14th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package javaLoopsMethodsClasses;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. public class Ex8_SumNumsFromTextFile {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.  
  11.         try {
  12.             BufferedReader in = new BufferedReader(new FileReader("Input.txt"));
  13.             String line;
  14.             int sum = 0;
  15.             while ((line = in.readLine()) != null) {
  16.                 sum += Integer.parseInt(line);
  17.             }
  18.             System.out.println(sum);
  19.             in.close();
  20.         } catch (java.io.FileNotFoundException nfe) {
  21.             System.out.println("Error");
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement