Write code to open and read from a file called numbers this

Write code to: open and read from a file called numbers this file contains a comma-separated list of numbers (example: 4, 5, 0, 3, 2, 1, 0, 7) count the number of \"Os\" in the file print the result to a file called output (example: the file contained 2 zeros) Use exception handling to handle the lO Exceptions. (Do not use \"throws lO Exception\")

Solution

import java.util.*;

import java.io.File;

import java.io.IOException;

public class ReadFile

{

    public static void main(String[] args)

    throws IOException

    {

        Scanner textfile = new Scanner(new File(\"Some_Numbers.txt\"));

        filereader(textfile);

    }  

    static void filereader(Scanner textfile)

    {

        int i = 0;

        int sum = 0;

        while(i <= 19)

        {

            System.out.println(textfile.nextInt());

            sum = sum + textfile.nextInt();

            i++;

        }

    }

}

 Write code to: open and read from a file called numbers this file contains a comma-separated list of numbers (example: 4, 5, 0, 3, 2, 1, 0, 7) count the number

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site