日历

« 2008-09-08  
 123456
78910111213
14151617181920
21222324252627
282930    

统计信息

  • 访问量: 138
  • 日志数: 2
  • 建立时间: 2007-03-12
  • 更新时间: 2007-09-27

RSS订阅

我的最新日志

  • build.xml 学习

    2007-9-27

    <?xml version = "1.0" encoding="GB2312" ?>
    <project default = "main" basedir = "." >
     <property name = "srcpath" value = "sdkongkong"/>
     <property name = "classpath" value = "build/classes"/>
     <target name = "init">
       <mkdir dir = "${classpath}"/>
     </target>
     <target name = "main" depends = "init">
       <javac srcdir = "${srcpath}" destdir = "${classpath}"/>
     </target>
     <target name = "clean" descrīption = "clean old class">
       <delete dir ="${classpath}"/>
     </target>
    </project>
  • 获取一个url的内容.

    2007-3-30

    WebPageReader.java

    package sdkongkong;
       import java.net.URL;
       import java.net.MalformedURLException;
       import java.net.URLConnection;
       import java.io.IOException;
       import java.io.BufferedReader;
       import java.io.InputStreamReader;

       public class WebPageReader {

          private static URLConnection connection;

          private static void connect( String urlString ) {
            try {
              URL url = new URL(urlString);
              connection = url.openConnection();
              System.out.println(connection.getClass());
            } catch (MalformedURLException e){
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          private static void readContents() {
            BufferedReader in = null;
            try {
              in = new BufferedReader(
                new InputStreamReader(
                  connection.getInputStream()));

              String inputLine;
              while (
                (inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
              }
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          public static void main(String[] args) {
            if (args.length != 1) {
              System.err.println("usage: java WebPageReader " + "<url>");
              System.exit(0);
            }
            connect(args[0]);
            readContents();
          }
       }

     

    使用方法,java WebPageReader + url(http://www.sina.com)

Open Toolbar