| Home | Family | Softwares | Resume | Activities |
import java.io.*;
public class IOTest
{
public static void main(string[]
args)
//To display error message if two arguments in the form of two file names is not
passed
if (args.length != 2)
{
System.out.println ("Syntax : Write names of two
files");
//Exit the program
System.exit(0);
}
{
try
{
// open arg[0] for
input
FileInputStream in = new
FileInputStream(args[0]);
// add
buffering to that
InputStream
BufferedInputStream bin = new
BufferedInputStream(in);
// open arg[1] for output and add buffering to it as
well
FileOutputStream out = new
FileOutputStream(args[1]);
BufferedOutputStream bout = new
BufferedOutputStream(out);
//now read as
long=as there is something to
read
byte bArray[] = new
byte[256];
int
nBytesRead;
while(bin.available( ) > 0
)
{
//read up
a block - remenber how many bytes
read
nBytesRead = bin.read(bArray);
// write that many bytes back out
starting
// at offset 0 in the
array
bout.write(bArray,
0,
nBytesRead);
}
bout.close();
}
catch(IOException
ioe)
{
System.out.print(ioe.tostring(
)
);
}
}
}