summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java b/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java
new file mode 100644
index 0000000..1493741
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/SaveURL.java
@@ -0,0 +1,35 @@
+/* SaveURL.java */
+
+import java.net.*;
+import java.io.*;
+
+public class SaveURL
+{
+ public static void main(String[] args)
+ {
+ if (args.length != 2) {
+ System.err.println(
+ "Usage: java SaveURL <url> <file>"
+ );
+ System.exit(1);
+ }
+ try {
+ URL url = new URL(args[0]);
+ OutputStream out = new FileOutputStream(args[1]);
+ InputStream in = url.openStream();
+ int len;
+ byte[] b = new byte[100];
+ while ((len = in.read(b)) != -1) {
+ out.write(b, 0, len);
+ }
+ out.close();
+ in.close();
+ } catch (MalformedURLException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ } catch (IOException e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
+ }
+} \ No newline at end of file