Question: Help correcting java program. I'll give you all the information so you understand completely. original question: Write a program that reads a file (provided as

Help correcting java program. I'll give you all the information so you understand completely.

original question:

Write a program that reads a file (provided as attachment to this assignment) and writes the file to a different file with line numbers inserted at the beginning of each line. Throw an exception if the file does not exist. An error message should result.

For example output should be:

1. This file contains

2. lines of text to

3. determine if you can

and so on and so fourth. The original .txt file reads:

This file contains lines of text to determine if you can properly read and write from a file.

The code im using reads:

import java.util.Scanner; import java.io.FileWriter; import java.io.File;

public class scanning { public static void main(String[] args)

{

//storing names of input/output files

final String txtIn="Lab4AInputfile.txt", txtOut="InputNumbered.txt";

try

{

//opens file for input Scanner in=new Scanner(new File(txtIn));

//opens file for output FileWriter out=new FileWriter(new File(txtOut));

int lineCount=1; //stores current line number

while(in.hasNextLine()) //while input file has next line to read

{

String line=in.nextLine(); //reading line

out.write(lineCount+". "+line+" "); //writing line with line number

lineCount+=1; //updating line number

}

//closing input and output files in.close(); out.close();

}

catch(Exception e) //catching exceptions

{

System.out.println(e); //error message

}

} }

My question is, where do I insert the .txt file,which is called "Lab 4 Input file.txt", to resolve this error? Help correcting java program. I'll give you all the information so you

scanning (Java Application) C:\Program Files\ava\jre1.8.0_20\bin\javaw.exe (Feb 21, 2020, 10:11:08 AM) java.io.FileNotFoundException: Lab4AInputfile.txt (The system cannot find the file specified) module 4 lab 4A > JRE System Library [JavaSE-1.8] . src >> # (default package)

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!