Question: Use Scanner to read int values from a file input.txt Read until end of file is reached Write all program output to a file output.txt

Use Scanner to read int values from a file input.txt

Read until end of file is reached

Write all program output to a file output.txt

Write all exceptions to a file error.txt

Output each number read

//What i have so far.

import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner;

public class lab5 {

public static void main(String[] args) throws FileNotFoundException { String inputFile = "input.txt"; Scanner file = new Scanner(new File(inputFile)); String outputFile = "output.txt"; String errorFile = "error.txt"; PrintWriter er = new PrintWriter(errorFile); int [] I = new int[1]; try{ I[10] = 2;}catch(Exception e){e.printStackTrace(); System.out.println(e.getMessage());} er.close(); PrintWriter out = new PrintWriter(outputFile); while(file.hasNext()){ out.println(file.next()); } out.close(); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!