ume that there is a data file named as “data.txt”. This data file contains integer values in multiple lines, as shown below. You are asked to write statements in the main() method to open the file, read and print out the total of all the values (should be 55). Place your code into try-catch block so that the FileNotFoundException will be caught and an error message will be printed if no such file exists. data.txt 1 2 3 4 5 6 7 8 9 10 import java.util.*;

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter14: Files And Streams
Section: Chapter Questions
Problem 2E: Create a program named FileComparison that compares two files. First, use a text editor such as...
icon
Related questions
Question

Assume that there is a data file named as “data.txt”. This data file contains integer values in multiple lines, as shown below. You are asked to write statements in the main() method to open the file, read and print out the total of all the values (should be 55). Place your code into try-catch block so that the FileNotFoundException will be caught and an error message will be printed if no such file exists.


data.txt
1 2 3
4 5 6
7 8 9 10


import java.util.*;
import java.io.*;
public class ReadAndPrint {
pubilc static void main() {

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning