Copy Code code as follows:
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.net.URL;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Java.util.Timer;
Import Java.util.TimerTask;
public class Getyininfo extends TimerTask {
private void Getcomexinfo () throws ioexception{
String res = "";
SimpleDateFormat dateformat=new SimpleDateFormat ("HH:mm:ss");
String Df=dateformat.format (New Date ());
URL url = new URL ("Http://www.jb51.netI");
Java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openconnection ();
Conn.connect ();
BufferedReader bf = new BufferedReader (New InputStreamReader (
Conn.getinputstream (), "GBK"));
String Line;
while (line = Bf.readline ())!= null) {
res + = line;
}
String agtd[]=res.split (",");
String re[]=agtd[0].split ("" ");
System.out.println ("COMEX" +df+ ":" +re[1]);
Bf.close ();
}
private void Gettdinfo () throws ioexception{
String res = "";
SimpleDateFormat dateformat=new SimpleDateFormat ("HH:mm:ss");
String Df=dateformat.format (New Date ());
URL url = new URL (http://www.jb51.net);
Java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openconnection ();
Conn.connect ();
BufferedReader bf = new BufferedReader (New InputStreamReader (
Conn.getinputstream (), "GBK"));
String Line;
while (line = Bf.readline ())!= null) {
res + = line;
}
String agtd[]=res.split (",");
String re[]=agtd[0].split ("" ");
System.out.println ("AG" +df+ ":" +re[1]);
Bf.close ();
}
@Override
public void Run () {
try {
Getcomexinfo ();
Gettdinfo ();
System.out.println ("---------------------------------------------");
catch (IOException e) {
E.printstacktrace ();
}
}
/**
* @param args
*/
public static void Main (string[] args) {
Timer timer = new timer ();
TimerTask T1 = new Getyininfo ();
Run the T1 task every 1000 milliseconds after 1000 milliseconds
Timer.schedule (t1,1000,5000);
/*try {
Thread.Sleep (10000);
catch (Interruptedexception e) {
E.printstacktrace ();
}
Timer.cancel ();
}
}