import java.io.*; import java.net.*; public class grabFile { public static void main(String[] args) throws Exception { if(args.length < 2) { System.out.println("Usage: java grabFile "); System.exit(1); } URL myFile = new URL(args[0]); URLConnection cc = myFile.openConnection(); int inputNums; try { // Open two streams. one for file output one for URI input. DataOutputStream Fout = new DataOutputStream(new FileOutputStream(args[1])); DataInputStream in = new DataInputStream(cc.getInputStream()); // While the stream is not -1 (EOF) while((inputNums = in.read()) != -1) { // Write to the picture file Fout.write(inputNums); } // Clean up. Fout.flush(); in.close(); Fout.close(); // ... and a little message System.out.println("Done."); } catch (Exception e) { System.err.println("Bah!" + e); } } }