In this section, you will learn how the data of multiple files is copied to another file. The java.io package provides this facility. For copping the data of multiple file, you need all files in a specified directory where the contents of all files are to
Copy multiple files
In this section, you will learn how the data of multiple files is copied to another file. The java.io package provides this facility. For copping the data of multiple file, you need all files in a specified directory where the contents of all files are to be copied to a specified file.
Description of program:
The following program copies the data of two files (source files) in a specified file (target file). At the time of execution of this program, it takes the number of file with their names that have to be copied. The last file is a target file that contains all data of the given source files. The method copyfile() copies the contents of all given files to a specific file. When all data are copied to specified file, it will display a message "File copied" otherwise Exception is thrown and data will not be be copied.
import java.io.*;
|
Output of program:
Here the data of "LAN.log" file and "CopyMultipleFiles.java" file are copied to the copy.txt file.
C:\vinod>javac CopyMultipleFiles.java C:\vinod>java CopyMultipleFiles Enter Number of files that have to be coppied: 3 Enter file name: LAN.log Enter file name: CopyMultipleFiles.java Enter file name: copy.txt File copied. |