写一个小程序,可以输入网站地址,然后就抓取网站的html,用来监控网站是否正常运行,抓取到表明网站正常运行,抓取不到表明网站挂网了,并弹出抓取不到提示框.这样的程序怎么实现呢??求大神指点。我是菜鸟,才刚学JAVA。

解决方案 »

  1.   


    URLConnection conn = new URL("http://www.baidu.com").openConnection();
    InputStream is = conn.getInputStream();

    OutputStream os = new FileOutputStream("c:/save.html");

    byte[] buffer = new byte[2048];

    int length = 0;

    while(-1 != (length = is.read(buffer, 0, buffer.length)))
    {
    os.write(buffer, 0, length);
    }

    is.close();
    os.close();
      

  2.   

    1的代码放在main方法里面,会生成c:/save.html
    隔一段时间让程序运行一次用Timer & TimerTask, LZ百度吧.http://wenku.baidu.com/view/84c20fbd960590c69ec376f5.html
      

  3.   

    这里有个php的程序能完成这个功能http://blog.csdn.net/y244360439/article/details/8098043