Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the files set up in the write place. I am just confused on how to use som

ID: 3865645 • Letter: I

Question

I have the files set up in the write place. I am just confused on how to use some of the desire methods to execute this code.

// Copy text file and insert line numbers Create a NetBeans project named AddLineNumbers following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans project AddLineNumbers and before you attempt to execute your application download and/or copy the text data file datalnput.txt from the course Blackboard to the AddLineNumbers project folder After you have created your NetBeans Project your application class should contain the following executable code: package addlinenumbers; public class AddLineNumbers f public static void main(Stringl args) Write the code for the main class as indicated below: package addlinenumber /* mport the Scanner class and all classes from java.io */ // Your code here public class AddLineNumbers public static void main( String [] args) /* Declare variable identifiers to handle text data input from the file and count/increment the linenumber*/ // Your code here * Start try block / // Your code here /* Instantiate Scanner object for data input from file "datalnput.txt". There should be no path specification as your input file should be located in your AddLineNumbers project folder*/ // Your code here

Explanation / Answer

package AddLineNumbers;

import java.io.*;
import java.util.*;


public class AddLineNumber{

    public static void main(String[] args){

          try {
              FileInputStream fstream = new FileInputStream("dataInput.txt"); //Assuming the input filename as textfile.txt
              BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
              String strLine;
              File fout = new File("dataOutput.txt");
              FileOutputStream fos = new FileOutputStream(fout);
              PrintWriter writer = new PrintWriter(fos);

              int count = 0;
             
              while ((strLine = br.readLine()) != null)   {
                  count++;
                  writer.println( Integer.toString(count) + "." + strLine );
              }
              System.out.println("Output file has been written");
              br.close();
              writer.close();
          }
          catch (FileNotFoundException e)
          {
               e.getMessage();
               e.toString();
               e.printStackTrace();
          }
          catch (IOException e)
          {
               e.getMessage();
               e.toString();
               e.printStackTrace();
          }
    }
}