Computer Science, asked by Anonymous, 4 hours ago

Write a java program to copy the content of one file in to another file​

Answers

Answered by MrTSR
1

The C0DE

import 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.

Attachments:
Answered by sunprince0000
1

Copyfile.java

import java.io.*;

import java.util.*;

class Copyfile {

public static void main(String arg[]) throws Exception {

Scanner sc = new Scanner(System.in);

System.out.print("Provide source file name :");

String sfile = sc.next();

System.out.print("Provide destination file name :");

Similar questions