-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSourceViewer2.java
More file actions
29 lines (26 loc) · 864 Bytes
/
SourceViewer2.java
File metadata and controls
29 lines (26 loc) · 864 Bytes
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
import java.io.*;
import java.net.*;
public class SourceViewer2 {
public static void main (String[] args) {
if (args.length > 0) {
try {
// Open the URLConnection for reading
URL u = new URL(args[0]);
URLConnection uc = u.openConnection();
try (InputStream raw = uc.getInputStream()) { // autoclose
InputStream buffer = new BufferedInputStream(raw);
// chain the InputStream to a Reader
Reader reader = new InputStreamReader(buffer);
int c;
while ((c = reader.read()) != -1) {
System.out.print((char) c);
}
}
} catch (MalformedURLException ex) {
System.err.println(args[0] + " is not a parseable URL");
} catch (IOException ex) {
System.err.println(ex);
}
}
}
}