Program to copy a file content in java is as follows:
import java.io.*;
class FileCopy
{
public static void main(String args[]) throws IOException
{
FileInputStream fin = new FileInputStream("d:/java/stk.java");
FileOutputStream fout = new FileOutputStream("d:/java/txtfile.txt");
int b;
while(true)
{
b = fin.read();
if(b == -1)
{
break;
}
System.out.print((char)b);
fout.write(b);
}
fin.close();
fout.close();
}
}
import java.io.*;
class FileCopy
{
public static void main(String args[]) throws IOException
{
FileInputStream fin = new FileInputStream("d:/java/stk.java");
FileOutputStream fout = new FileOutputStream("d:/java/txtfile.txt");
int b;
while(true)
{
b = fin.read();
if(b == -1)
{
break;
}
System.out.print((char)b);
fout.write(b);
}
fin.close();
fout.close();
}
}
No comments:
Post a Comment