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.
Here is the code:
The above code makes a copy of the file.
Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles