Advertisement
Guest User

Untitled

a guest
May 19th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. public class _08_SumNumbersFromTextFile {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         BufferedReader br = null;
  10.         int result = 0;
  11.         try {
  12.  
  13.             String currentLine;
  14.  
  15.             br = new BufferedReader(new FileReader("Input.txt"));
  16.  
  17.             while ((currentLine = br.readLine()) != null) {
  18.                 result += Integer.parseInt(currentLine);
  19.             }
  20.             System.out.println(result);
  21.  
  22.         } catch (IOException e) {
  23.             System.out.println("Error!");
  24.         } finally {
  25.             try {
  26.                 if (br != null){
  27.                     br.close();
  28.                 }
  29.             } catch (IOException ex) {
  30.                 ex.printStackTrace();
  31.             }
  32.         }
  33.        
  34.     }
  35.    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement