Java Reference
In-Depth Information
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
class Copy
{
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("usage: java Copy srcfile dst-
file");
return;
}
FileInputStream fis = null;
try
{
fis = new FileInputStream(args[0]);
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(args[1]);
int b; // I chose b instead of byte because
byte is a reserved word.
while ((b = fis.read()) != -1)
fos.write(b);
}
catch (FileNotFoundException fnfe)
{
String msg = args[1]+" could not be created,
possibly because "+
"it might be a directory";
System.err.println(msg);
}
catch (IOException ioe)
Search WWH ::




Custom Search