Question: please solve using java code and take a screenshot of the code Lab File 1/0 & Exceptions Write a program that reads an input file

 please solve using java code and take a screenshot of the

code Lab File 1/0 & Exceptions Write a program that reads an

please solve using java code and take a screenshot of the code

Lab File 1/0 & Exceptions Write a program that reads an input file and print the input file data to an output file but with the following additions 1. each line in the outputfile is prefixed with the current line number, first line with 1. Second line with 2. etc 2. all empty lines or lines containing all blanks are not to be written to the output file 3. The program must not throw a FileNotFoundException, rather it should catch the exception in the program and ask the user again for a new input file name. Keep repeating until no exception is generated from opening the file to read and write. Sample run if file Lab.java does not exist and Lab4.java exists Please enter input file name: Lab.java Please enter outputfile name: Lab.out File does not exist Please enter input file name: Lab4.java Please enter outputfile name: Lab.out Input File: public class Lab4 1 public static void main(String[] args) throws FileNotFoundException [ String a = "c3.txt"; String x = "xyz.txt"; File b = new File(a); Scanner in = new Scanner (b); Scanner key = new Scanner(System.in); String data = ""; while (in.hasNextLine()) data + in.nextLine(); } String d = key.next(); d = key.next(); d = d + data; System.out.println(d); 1 } Output file public class Lab 1. 2. 3. public static void main(String[] args) throws FileNotFoundException 5. 6. 7. 8. 9. 10. 11. 12. 13. String a = "c3.txt"; String x = "xyz.txt"; File b = new File(a); Scanner in = new Scanner (b); Scanner key = new Scanner (System.in); String data = ""; while (in.hasNextLine()) [ data += in.nextLine(); } String d = key.next(); d = key.next(); d = d + data; System.out.println(d); 14. 15. 16. 17. 18. 19. 20. 21. } }

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!