Quantcast
Channel: Java mon amour
Viewing all articles
Browse latest Browse all 1124

Poor man's wget for Windows

$
0
0
Windows not only is an awfully stinking mastodon, but it even lacks the most basic tools commonly available on Linux, such as telnet and wget.

I have found a bare bones wget implementation for Java and duly simplified (I love to strip away all useless exception handling)


import java.io.InputStream;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
import java.net.*;

public class JGet {
public static void main(String[] args) throws Exception {
if ((args.length != 1)) {
System.err.println("\nUsage: java JGet [urlToGet]");
System.exit(1);
}
String url = args[0];
URL u;
InputStream is = null;
DataInputStream dis;
String s;
try {
u = new URL(url);
is = u.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine()) != null) {
System.out.println(s);
}
} finally {
is.close();
}
}
}


All the credits to Alexander.

Viewing all articles
Browse latest Browse all 1124

Trending Articles