|
Java™ by example!
|
|
|
How do I copy a file?
Use FileInputStream and FileOutputStream, these classes treat files as byte streams as opposed to FileReader and FileWriter that treat files as character streams. To copy a file, open the source file with FileInputStream and call the read() method until end-of-file, occurs when read() return -1. In the meantime, use the write method to write that byte to the newly created file. You can make this process much more performant by using BufferedInput and BufferedOutput Streams.
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|