InterviewSolution
| 1. |
Write a java program to copy the content of one file in to another file |
Answer» The C0DEimport java.io.FILEINPUTSTREAM; import java.io.FileOutputStream; class File_demo { public static void main(String[] args) { byte[] array = new byte[50]; try { FileInputStream sourceFile = new FileInputStream("input.txt"); FileOutputStream destFile = new FileOutputStream("output.txt"); // reads all DATA from input.txt sourceFile.read(array); // writes all data to newFile destFile.write(array); System.out.println("The input.txt file is COPIED to newFile."); // CLOSES the stream sourceFile.close(); destFile.close(); } CATCH (Exception e) { e.getStackTrace(); } } } If you run the program the contents of input.txt will be copied to output.txt file. See attachment for result. |
|