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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started