728x90 AdSpace

Trending

how-to-copy-file-in-java

import java.io.*;
import java.util.*;
class CopyFile{
public static void main(String arg[]){
try{
Scanner s=new Scanner(System.in);
System.out.println("Enter Original File Name :-");
String filename=s.next();
//================================opening the file to read the content
FileReader fr=new FileReader(filename);
BufferedReader br=new BufferedReader(fr);
System.out.println("Enter Filename to which content should be copied:");
String filenamec=s.next();
FileWriter fr1=new FileWriter(filenamec);
BufferedWriter br1=new BufferedWriter(fr1);
String filecontent;
filecontent=br.readLine();
while(filecontent!=null)
{
br1.write(filecontent);
filecontent=br.readLine();
}
br1.close();
br.close();
System.out.println("file "+filename+" content copied to "+filenamec);
}catch(Exception e){
System.out.println("fileNotFound");
}
}
}
how-to-copy-file-in-java Reviewed by B AProgrammer on 10:52 Rating: 5 import java.io.*; import java.util.*; class CopyFile{ public static void main(String arg[]){ try{ Scanner s=new Scanner(System.in); S...

1 comment: