Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Solve each equation in Exercise 1 for x?

Answered: 1 week ago

Question

3. Evaluate a Web-based training site.

Answered: 1 week ago