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
HACTEHA [7]
4 years ago
14

Please add comments to your program to explain it. Thank you!

Engineering
1 answer:
Step2247 [10]4 years ago
8 0

Answer / Explanation:

(1) We should first understand that the input filename are passed in as the first command arguments at command line, respectively.

To do this, we import the data file:

So we have,

import java.io.*;

/**

*  Makes a copy of a file.  The original file and the name of the

*  copy must be given as command-line arguments.  In addition, the

*  first command-line argument can be "-f"; if present, the program

*  will overwrite an existing file; if not, the program will report

*  an error and end if the output file already exists.  The number

*  of bytes that are copied is reported.

*/

public class CopyFile {

  public static void main(String[] args) {

     String sourceName;   // Name of the source file,  

                          //    as specified on the command line.

     String copyName;     // Name of the copy,  

                          //    as specified on the command line.

     InputStream source;  // Stream for reading from the source file.

     OutputStream copy;   // Stream for writing the copy.

     boolean force;  // This is set to true if the "-f" option

                     //    is specified on the command line.

     int byteCount;  // Number of bytes copied from the source file.

     

     /* Get file names from the command line and check for the  

        presence of the -f option.

(2)   If the command line is not one

        of the two possible legal forms, print an error message and  

        end this program. */

   

     if (args.length == 3 && args[0].equalsIgnoreCase("-f")) {

        sourceName = args[1];

        copyName = args[2];

        force = true;

     }

     else if (args.length == 2) {

        sourceName = args[0];

        copyName = args[1];

        force = false;

     }

     else {

        System.out.println(

                "Usage:  java CopyFile <source-file> <copy-name>");

        System.out.println(

                "    or  java CopyFile -f <source-file> <copy-name>");

        return;

     }

     

     /* Create the input stream.  If an error occurs, end the program. */

     

     try {

        source = new FileInputStream(sourceName);

     }

     catch (FileNotFoundException e) {

        System.out.println("Can't find file \"" + sourceName + "\".");

        return;

     }    

     /* If the output file already exists and the -f option was not

        specified, print an error message and end the program. */

   

     File file = new File(copyName);

     if (file.exists() && force == false) {

         System.out.println(

              "Output file exists.  Use the -f option to replace it.");

         return;  

    }      

     /* Create the output stream.  If an error occurs, end the program. */

     try {

        copy = new FileOutputStream(copyName);

     }

     catch (IOException e) {

        System.out.println("Can't open output file \"" + copyName + "\".");

        return;

     }

     

   (3)   /* Copy one byte at a time from the input stream to the output

        stream, ending when the read() method returns -1 (which is  

        the signal that the end of the stream has been reached).  If any  

        error occurs, print an error message.  Also print a message if  

        the file has been copied successfully.  */  

     byteCount = 0;

     

     try {

        while (true) {

           int data = source.read();

           if (data < 0)

              break;

           copy.write(data);

           byteCount++;

        }

        source.close();

        copy.close();

        System.out.println("Successfully copied " + byteCount + " bytes.");

     }

     catch (Exception e) {

        System.out.println("Error occurred while copying.  "

                                  + byteCount + " bytes copied.");

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

     }    

  }  // end main()  

} // end class CopyFile

You might be interested in
What is 220 C in degrees Fahrenheit (F)?
8_murik_8 [283]

Answer:

428°F

Explanation:

The equation to convert degrees Celsius to degrees fahrenheit is

°F (degrees fahrenheit) = (9/5 * °C (degrees celsius) ) + 32

°F = (9/5 * 220 °C (degrees celsius)) +32 = 428 °F (degrees fahrenheit)

4 0
3 years ago
Write a Pig script and run it in local mode on this data to find out the top 10 states according to the land area. Since you wan
ELEN [110]

Explanation:

Apache Pig script execution modes

Local mode: In 'local mode', you can run the pig script on the local file system. In this case, you don't need to store the data in the Hadoop HDFS file system, instead you can work with the data stored in the local file system.

MapReduce mode: In 'MapReduce mode', the data must be stored in the HDFS file system and you can process the data with the help of pig script.

Apache Pig Script in MapReduce mode

Let's say our task is to read data from a data file and display the required contents in the terminal as output.

The sample data file contains the following data:

Txt information file - Apache Pig Script - Edureka

Save the text file with the name 'information.txt'

The sample data file contains five First Name, Last Name, Mobile Number, City, and Profession columns separated by the tab key. Our task is to read the contents of this HDFS file and display all the columns of these records.

To process this data using Pig, this file must be present in Apache Hadoop HDFS.

Command: hadoop fs –copyFromLocal /home/edureka/information.txt / edureka

3 0
3 years ago
Question 9 of 10 (1 point) Jump to Question:
Katen [24]

Answer:

A.

Explanation:

8 0
4 years ago
Read 2 more answers
Your uncle has given you a newmonitor for your computer. When you attempt to connect it, you notice that none of the ports on th
juin [17]

Answer:

Go on amazon and look for HDMI -> (VGA/DVI/HDMI) what ever you need adapters.

6 0
3 years ago
What is polarized electrical receptacle used for
lidiya [134]

Answer:

they are used for electrical currents so that they can flow along the appropriate wires in the circuit

Explanation:

4 0
4 years ago
Other questions:
  • A one-dimensional slab without heat generation has a thickness of 20 mm with surfaces main- tained at temperatures of 275 K and
    10·1 answer
  • Find the equivalent impedance Zeq seen by the source when Vs = 5 cos (2t) v, C = 2 F, R = 1 Ω and L = 1 H. (Give angles in degre
    9·1 answer
  • The closed tank of a fire engine is partly filled with water, the air space above being under pressure. A 6 cm bore connected to
    9·1 answer
  • Water flows at 0.1 m3 /s through the 100– mm–diameter nozzle and strikes the vane on the 150–kg cart, which is originally at res
    13·1 answer
  • Why some types of aggregate are susceptible to damage from repeated freezing and thawing? Explain.
    5·1 answer
  • Moist air enters a duct at 10 oC, 70% relative humidity, and a volumetric flow rate of 150 m3/min. The mixture is heated as it f
    5·1 answer
  • A hydraulic cylinder has a 125-mm diameter piston with hydraulic fluid inside the cylinder and an ambient pressure of 1 bar. Ass
    8·1 answer
  • Naval vessels protection John's require the non-military vessels remain at least 100 yards away from the US naval vessels and op
    5·1 answer
  • Chaplets are used to support a sand core inside a sand mold cavity. The design of the
    13·1 answer
  • Which of the following statements about pitot-static systems is FALSE? a). A pitot probe measures the Total Pressure of the free
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!