1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/**
* Copyright (c) 2001-2020 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://robocode.sourceforge.io/license/epl-v10.html
*/
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
/**
* @author Pavel Savara (original)
*/
public class Loader {
public static void main(String[] args) throws IOException {
for (int i = 2; i < args.length; i++) {
System.out.print("Downloading " + args[0] + args[i] + " to " + args[1] + " [...");
downloadFile(args[0], args[1], args[i]);
System.out.println("...] done");
}
}
private static void downloadFile(String libraries, String directory, String file) throws IOException {
URL url = new URL(libraries + file);
final URLConnection con = url.openConnection();
InputStream is = null;
FileOutputStream fos = null;
try {
is = con.getInputStream();
fos = new FileOutputStream(directory + file);
do {
final int b = is.read();
if (b == -1) {
break;
} else {
fos.write(b);
}
} while (true);
} finally {
if (fos != null) {
fos.close();
}
if (is != null) {
is.close();
}
}
}
}
|