I am trying to find very good code example for copying a file from one directory to another directory in Java.
I have to write a program in my application for copying one file from a directory to another directory. How to achieve this? Is there any API in Java which will help in writing code for copy the file in just few lines of code?
Is there any size issue while copying the file from one directory to another directory? My program should be able to copy the file of any size. Our program does not know the size of file and the production environment users many copy the file of any size even in 4-5 GB size.
Do you think Java program will be able to do this job correctly? Can anyone share me the good and fast code example for copying the file from one directory to another directory in Java?
Java provides API for managing the files in Java. You can manage the file of any size in Java. Java program will work file even if your client provides file of big size say 5-6GB.
In java java.io.File class is used to work with file. This class is used to create, read, edit, find and update the files. You can use this class to move the file from one directory to another directory.
One method is to read the content from a using FileInputStream and then write the content into another file using FileOutputStream class.
Read the tutorial at How to copy a file.