-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLast24.java
More file actions
36 lines (32 loc) · 1.08 KB
/
Last24.java
File metadata and controls
36 lines (32 loc) · 1.08 KB
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
import java.io.*;
import java.net.*;
import java.util.*;
public class Last24 {
public static void main (String[] args) {
// Initialize a Date object with the current date and time
Date today = new Date();
long millisecondsPerDay = 24 * 60 * 60 * 1000;
for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[i]);
URLConnection uc = u.openConnection();
System.out.println("Original if modified since: "
+ new Date(uc.getIfModifiedSince()));
uc.setIfModifiedSince((new Date(today.getTime()
- millisecondsPerDay)).getTime());
System.out.println("Will retrieve file if it's modified since "
+ new Date(uc.getIfModifiedSince()));
try (InputStream in = new BufferedInputStream(uc.getInputStream())) {
Reader r = new InputStreamReader(in);
int c;
while ((c = r.read()) != -1) {
System.out.print((char) c);
}
System.out.println();
}
} catch (IOException ex) {
System.err.println(ex);
}
}
}
}