1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
finlep [7]
3 years ago
8

Write a program that reads a file containing text. Read each line and send it to the output file, preceded by line numbers. If t

he input file is Mary had a little lamb Whose fleece was white as snow. And everywhere that Mary went, The lamb was sure to go! then the program produces the output file /* 1 */ Mary had a little lamb /* 2 */ Whose fleece was white as snow. /* 3 */ And everywhere that Mary went, /* 4 */ The lamb was sure to go! The line numbers are enclosed in /* */ delimiters so that the program can be used for numbering Java source files. Prompt the user for the input and output file names.

Computers and Technology
1 answer:
Shtirlitz [24]3 years ago
7 0

Answer:

I am writing a JAVA program:

import java.io.FileReader;  // class used for reading data from a file

import java.io.IOException;  //class used for handling exceptions

import java.io.PrintWriter;  // class used to printing or writing formatted data. It is used when the data to be written contains text and numbers

import java.util.Scanner;   // class used to take input from the user

public class Main  {  //start of the class

public static void main(String[] args)  {//start of main() function body

Scanner input = new Scanner(System.in);  //creates Scanner class object

System.out.print("Enter the input file name: ");  // prompts user to enter the input file name

String input_file = input.next();  //to  read and return the token i.e. input file name and store this into input_file String type variable

System.out.print("Enter the output file name: "); // prompts user to enter the output file name

String output_file = input.next();   /to  read and return the token i.e. output file name and store this into output_file String type variable

try   {/* try  defines a chunk of code to be tested for errors during the execute of this chunk. its a code block for reading from input file and writing to output file. This handles the exception if program cannot create or write to the file indicated. */

   FileReader inFile = new FileReader(input_file);  //creates object inFile of FileReader class to read the input_file contents

   Scanner scan = new Scanner(inFile);  //read and scans the input file

   PrintWriter outFile = new PrintWriter(output_file);  //creates object outFile of PrintWriter class to write to the output file. It is used to write output data in a readable text form.

   int count = 1;    //counts the line number      

   while (scan.hasNextLine())  {  //loop keeps checking for the next line in input file

    String lines = scan.nextLine();  // reads the entire line of the input file and stores that line contents in String lines

    outFile.println("/* " + count + " */ " + lines);  //each line represented with line number enclosed in /* */

    count++;  }   //increments the line number at each iteration    

    outFile.close();        }  //closes the output file after writing the contents from input file with each line of the input file enclosed in  /* */

catch (IOException e)  {  // catching the IOException and prints the following message if program cannot create input_file or write to the output_file

   System.out.println("Error processing file: " + e);    }     }   }

Explanation:

The program is well explained in the comments mentioned with each statement of the above program. The user is prompted to enter input and output file names. Then the program uses a while loop that scans through lines of the input file and count variable counts each line of input file. Then at each iteration the count variable counts a line of input file and line number of each line of the input file is enclosed in /* */ delimiters. The contents of input file, in which the line numbers of text lines of the input file are enclosed in /* */ delimiters, is written to the output file.

The screenshot of the program is attached along with the output file produces as a result of this program execution.

You might be interested in
0111101101010110101110110001001011101001011101101010101010110101
rodikova [14]

Answer:

binary digits in computer system it belongs

4 0
3 years ago
An ftp ____ is a computer that allows users to upload and/or download files using ftp.
Brums [2.3K]
<span>An ftp server is a computer that allows users to upload and/or download files using ftp.</span>
7 0
3 years ago
Davids family took him to a hospital as he was suffering from a sericous ailment
marta [7]

Answer:

Here are some other sentences which always demonstrate that perhaps the hospital operates with either the help of technology, which is given below.

Explanation:

  • As eventually as he was acknowledged or confessed, the medical records of David would be documented by the medical practitioners.
  • David was therefore positioned through an ICU during which his heart rate had been monitored closely (those same types of machinery were directly linked to the desktops in position to obtain comment of his vital statistics.)
7 0
2 years ago
Sorting Records in a Form
Naya [18.7K]

Answer:

1. Open the form in the standard form view.

2. Put the cursor in the field to use for sorting.

3. Open the Home tab

4. In the Sort & Filter group, click ascending or descending

Explanation:

Took the test :)

7 0
3 years ago
When one makes a social media post, what happens on other devices with the same app?
victus00 [196]

Answer:

An alert appears on the other devices

Explanation:

On social media platforms, whenever some one make a post, all the person who are using that social media app and present in the friend circle of that particular person receive an alert containing the information of the post.

The alert that received by different users on a social media platform is known as Notification. This notification is a type of text, in which the activity performed by post creator is mentioned, this text is received with the tone called notification tone.

The purpose of the alert is to informs the friends who are using that social media platform that a post has been published by someone.  

8 0
3 years ago
Other questions:
  • Finding information on the web was made easier by _____________, which provide on-screen menus, making navigation of the web as
    12·1 answer
  • When you align or size a group of selected controls, the changes are made relative to the
    14·1 answer
  • The page orientation in which the page width is greater than the page height is called
    8·1 answer
  • Please help, Tech class!!
    14·1 answer
  • What is a good analogy for explaining the actions of a compiler?
    10·1 answer
  • Please an urgent answer<br>will give brainliest<br>what is the definition of bucket address.​
    13·1 answer
  • How do operating system work?
    5·1 answer
  • What can hack or code can I use to get a shadow or frost dragon in adopt me
    6·2 answers
  • You are setting up a home network for your friend. She has students visiting her home regularly for lessons and wants to provide
    14·1 answer
  • You are the security analyst for your organization and have discovered evidence that someone is attempting to brute-force the ro
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!