In this section, you will learn how to copy a file using Java IO library.

How to copy a file

In this section, you will learn how to copy a file using Java IO library. For
this, we have declared a function called copyfile() which creates two File
instances to specify source and destination file respectively. It then creates
InputStream instance for the input object and OutputStream instance for the
output object. The read() method of an InputStream class reads the byte
value from the stream until there is a data in the stream from the source file.
The write() method of OutputStream class writes this value into the destination
file.