Question: String fileName is read from input. The try block opens a file named fileName for output. Three integers are read from input, and each integer
String fileName is read from input. The try block opens a file named fileName for output. Three integers are read from input, and each integer is written into the file. Write the finally block to perform the following tasks, if the output file is open:
Write to the file numValuesRead, followed by values read" and a newline.
If numValuesRead is greater than zero, write to the file "Last value is: followed by chiveLast and a newline.
Close the file. import java.util.Scanner;
import java.ioFileOutputStream;
import java.ioPrintWriter;
public class WriteLastChiveFile
public static void mainString args
Scanner scnr new ScannerSystemin;
PrintWriter chiveInWriter null;
String fileName;
int chiveValue;
int numValuesRead ;
int chiveLast ;
fileName scnrnext;
try
chiveInWriter new PrintWriternew FileOutputStreamfileName;
for numValuesRead ; numValuesRead ; numValuesRead
chiveValue scnrnextInt;
chiveInWriter.printlnchiveValue;
chiveLast chiveValue;
catch Exception e
System.out.printlnError;
Your code goes here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
