19. 3. 3. 获取更新的过去24小时内的文件 Get files updated last 24 hours

19. 3. 3. 获取更新的过去24小时内的文件 Get files updated last 24 hours

import java.io.BufferedInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.net.URLConnection; import java.util.Date; public class URLtest3 { public static void main(String[] args) throws Exception{ Date today = new Date(); System.out.println(today);//Fri Oct 21 16:58:50 CST 2011 //PerDay:每天 long millisecondsPerDay = 24 * 60 * 60 * 1000;//milli:毫、千分之一、这是一天 URL u = new URL("http://www.163.com"); URLConnection uc = u.openConnection(); //将此 URLConnection 的 ifModifiedSince 字段的值设置为指定的值。 uc.setIfModifiedSince((new Date(today.getTime() - millisecondsPerDay)).getTime()); InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in); int c ; while((c = r.read()) != -1){ System.out.print((char)c); } } }