Program to copy file content into another file
for example
create two text files
file1.txt content is copied into file2.txt
import java.io.*;
class Filedemo
{
public static void main(String args[]) throws FileNotFoundException,IOException
{
FileInputStream fis=new FileInputStream("file1.txt");
FileOutputStream fos=new FileOutputStream("file2.txt");
int data;
while((data=fis.read())!=-1)
{
fos.write(data);
System.out.println("successfully file1 is copied into file2");
}
}//main
}//class
output
for example
create two text files
file1.txt content is copied into file2.txt
import java.io.*;
class Filedemo
{
public static void main(String args[]) throws FileNotFoundException,IOException
{
FileInputStream fis=new FileInputStream("file1.txt");
FileOutputStream fos=new FileOutputStream("file2.txt");
int data;
while((data=fis.read())!=-1)
{
fos.write(data);
System.out.println("successfully file1 is copied into file2");
}
}//main
}//class
output
No comments:
Post a Comment