Memory Mapped I/O Example: Old Way
import java.io.*;
public class FileCopier {
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("Usage: java FileCopier infile outfile");
return;
}
try {
copy(args[0], args[1]);
}
catch (IOException e) {
System.err.println(e);
}
}
public static void copy(String inFile, String outFile)
throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(inFile);
out = new FileOutputStream(outFile);
for (int b = in.read(); b != -1; b = in.read()) {
out.write(b);
}
}
finally {
try {
if (in != null) in.close();
}
catch (IOException e) {}
try {
if (out != null) out.close();
}
catch (IOException e) {}
}
}
}