import java.io.*; import java.nio.*; import java.nio.channels.*; import java.net.*; class DupFile { void copyThruChannel(String fname) throws Exception { File f = new File(fname); FileInputStream fin = new FileInputStream(f); int len = (int) f.length(); FileChannel fc = fin.getChannel(); System.out.println("allocating buff"); ByteBuffer myBB = ByteBuffer.allocate(len); int bytesRead = fc.read(myBB); myBB.flip(); System.out.println("getting fout channel"); FileOutputStream fos = new FileOutputStream(fname+".copy"); FileChannel fco = fos.getChannel(); int bytesWritten = fco.write(myBB); fco.close(); } public static void main(String a[]) throws Exception { DupFile client = new DupFile(); client.copyThruChannel(a[0]); } }