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
Given a two-dimensional steady inviscid air flow field with no body forces described by the velocity field given below. Assuming
kolbaska11 [484]

Answer:

the pressure gradient in the x direction = -15.48Pa/m

Explanation:

  • The concept of partial differentiation was used in the determination of the expression for u and v.
  • each is partially differentiated with respect to x and the appropriate substitution was done to get the value of the pressure gradient as shown in the attached file.

4 0
3 years ago
Hi I don't know of yall remeber me, but I'm Jadin aka J. I am looking for my friend group, that I have missed but can't find cau
kirill [66]

Answer:

The young lady was his daughter.The shoemaker was frightened when he saw that she wants to sit near him and took his knife to frighten her and leave him alone to do his work

Explanation:

could uh name them since if i know any i would surely tryin help

7 0
2 years ago
identify which country has an absolute advantage in production of cookies and which has the absolute advantage in production of
nirvana33 [79]

a) Question Completion:

INPUT HOURS OF LABOR

Country   Cookies      Milk

Atlantis       2 hours   1 hour

Neverland  4 hours   1 hour

Answer:

1. Atlantis has the absolute advantage in the production of cookies.

2. No country has the absolute advantage in the production of milk.

Explanation:

Absolute advantage refers to superior production capability.  It is determined when a country, for example, has the ability to produce a particular good or service at lower cost or more efficiently (i.e. with less resources) than the other country.  In the scenario above, Atlantis has an absolute advantage in the production of cookies because it can produce the same quantity of cookies using 2 labor hours that Neverland can produce using 4 labor hours.  But for the production of milk, Atlantis and Neverland share the same comparative advantage less they can use less labor hours to produce milk than they can produce cookies.

5 0
3 years ago
A water tank filled with solar-heated water at 40°C is to be used for showers in a field using gravity-driven flow.
Alenkasestr [34]

Answer:

yes sir

Explanation:

4 0
3 years ago
Guess my birthday it’s in September you should be good with it
Paraphin [41]

Answer:

spetember 7th

Explanation:

5 0
3 years ago
Other questions:
  • A certain process requires 3.0 cfs of water to be delivered at a pressure of 30 psi. This water comes from a large-diameter supp
    9·1 answer
  • The ________________ attraction between the Earth and the moon is ______________ on the side of the Earth that happens to be ___
    5·1 answer
  • By using order of magnitude analysis, the continuity and Navier-Stokes equations can be simplified to the Prandtl boundary-layer
    9·1 answer
  • Suppose you have two arrays: Arr1 and Arr2. Arr1 will be sorted values. For each element v in Arr2, you need to write a pseudo c
    11·1 answer
  • (a) calculate the moment at point "c", where point "c" is the square 3'' below the centroid
    13·1 answer
  • What speeds did john j montgomerys gliders reach
    12·1 answer
  • True or false for the 4 questions?
    8·1 answer
  • A ruptured desiccant bag in a reciever-driver is usually caused by what?​
    13·1 answer
  • When hermetic refrigerant motor-compressors are designed to operate continuously at currents greater than 156 percent of the rat
    10·1 answer
  • 7. If you can't ignore a distraction, what should you do?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!