Ask Question
9 November, 00:23

Create your own unique Java application to read all data from the file echoing the data to standard output. After all data has been read, display how many data were read. For example, if 10 integers were read, the application should display all 10 integers and at the end of the output, print "10 data values were read"

+1
Answers (1)
  1. 9 November, 03:56
    0
    Output

    The values read are:

    25

    3

    4

    65

    7

    9

    5

    6

    1

    11

    10 data values were read

    Explanation:

    Below is the Java program to read all data from the file echoing the data to standard output and finally displaying how many data were read:-

    import java. io. File;

    import java. io. FileNotFoundException;

    import java. util. Scanner;

    public class MyFileReader {

    public static void main (String[] args) {

    int num, counter=0;

    File file=new File ("numbers. txt");

    try {

    Scanner input=new Scanner (file);

    System. out. println ("The values read are: ");

    while (input. hasNext ()) {

    num=input. nextInt ();

    System. out. println (num);

    counter+=1;

    }

    System. out. println (counter+" data values were read");

    } catch (FileNotFoundException e) {

    / / TODO Auto-generated catch block

    e. printStackTrace ();

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Create your own unique Java application to read all data from the file echoing the data to standard output. After all data has been read, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers