Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- public class _08_SumNumbersFromTextFile {
- public static void main(String[] args) {
- BufferedReader br = null;
- int result = 0;
- try {
- String currentLine;
- br = new BufferedReader(new FileReader("Input.txt"));
- while ((currentLine = br.readLine()) != null) {
- result += Integer.parseInt(currentLine);
- }
- System.out.println(result);
- } catch (IOException e) {
- System.out.println("Error!");
- } finally {
- try {
- if (br != null){
- br.close();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement