/*java program to get two file-name as a command line argument
source - file and destination file and copy data from source file to destination file.*/
PROGRAM CODE--
import java.io.*;
class CopyFile
{
public static void main(String ar[]) throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
//check both files has been specified or not
if(ar.length!=2)
{
System.out.println("Usage : CopyFile from to");
return;
}
//copy a file
try
{
fin=new FileInputStream(ar[0]);
fout=new FileOutputStream(ar[1]);
do
{
i=fin.read();
if(i!=-1)
fout.write(i);
}while(i!=-1); //-1 indictate the end of file..
fin.close();
fout.close();
}catch(IOException ae)
{
System.out.println("Error to copy a data ");
}
finally
{
System.out.println("Successfully data is copied");
}
}
}
source - file and destination file and copy data from source file to destination file.*/
PROGRAM CODE--
import java.io.*;
class CopyFile
{
public static void main(String ar[]) throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
//check both files has been specified or not
if(ar.length!=2)
{
System.out.println("Usage : CopyFile from to");
return;
}
//copy a file
try
{
fin=new FileInputStream(ar[0]);
fout=new FileOutputStream(ar[1]);
do
{
i=fin.read();
if(i!=-1)
fout.write(i);
}while(i!=-1); //-1 indictate the end of file..
fin.close();
fout.close();
}catch(IOException ae)
{
System.out.println("Error to copy a data ");
}
finally
{
System.out.println("Successfully data is copied");
}
}
}
THIS IS A SOURCE FILE FROM WHERE DATA IS COPY--
OUTPUT OF ABOVE PROGRAM--
THIS IS A DESTINATION FILE WHERE DATA IS COPIED...





Comments
Post a Comment