Search Here

Java program to copy a text file from A.txt to B.txt


/* Copy a text file A.txt to B.txt */

import java.io.*;
class Main
{
 public static void main(String args[])
 {
  FileInputStream fstream;
  DataInputStream in;
  FileOutputStream out;
  PrintStream p;
  
  try
  {
   fstream=new FileInputStream("A.txt");
   in=new DataInputStream(fstream);
   out=new FileOutputStream("B.txt");
   p=new PrintStream(out);
   
   while(in.available()!=0)
   {
    String st=in.readLine();
    p.println(st);
   }
   in.close();
   p.close(); 
   System.out.println("A.txt is successfully copied to B.txt");
  }
  catch(Exception e)
  {
   System.err.println(e);
  }
 }
}

JAVA program to copy a text file from A.txt to B.txt
Output

No comments:

Post a Comment