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://hq.sinajs.cn /? List = hf_SI ");
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.111cn.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 ();*/
}
}