CSDN博客

img xkou

java 学习的第一天

发表于2004/6/28 22:37:00  946人阅读

考试之前老复习实在是没有意思,在blog 上看到很多人都写了学习java 的文章,看了看,觉得很有意思,于是也下了一个从来没听说过的Eclipse安装上,试着弄弄,这个软件还不错,在我机子上可以正确运行,写了个helloword ,(对面向对象还是不够熟练,写得少啊).

然后就通过url 对象获得网页的内容

import java.net.*;
import java.io.*;

public class GetURLInfo{
 public static void main(String arg[]) throws Exception {
  URL Aurl=new URL("
http://stu.sdai.edu.cn/");
  BufferedReader in = new BufferedReader(new InputStreamReader(Aurl.openStream()));
  String inputLine;
  while ((inputLine = in.readLine()) != null)
   System.out.println(inputLine);
  in.close();
 }
}

感觉和c#差不多。后来又学着用了用socket

Socket socket=new Socket("202.194.85.2",80);
      BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
      PrintWriter os=new PrintWriter(socket.getOutputStream());
      BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
      int i=0;
      String getline;
      while(i<5){
       os.println("GET /bbs/postfo.asp?t_id=3073&l_id=39&action=do HTTP/1.1");
       os.println("Accept: */*");
       os.println("Referer:
http://stu.sdai.edu.cn/bbs/postfo.asp?t_id=3073&l_id=39&action=do");
       os.println("Accept-Language: zh-cn");
       os.println("Accept-Encoding: gzip, deflate");
       os.println("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)");
       os.println("Host: stu.sdai.edu.cn");
       os.println("Connection: Keep-Alive");
       os.println("Cookie: XPlinklinkfylogin=cpb; XPlinklinkfeiyue=userid=874&password=bd8080f72d8b220a&username=wobuzhi; ASPSESSIONIDQGQQQLCY=HDIMHDCDMIKGELGOHOJLNPKL/n/n/n");
       os.flush();
       System.out.println("Client:"+"已发送"+i);
       System.out.println("Server:"+is.readLine());
       
       i++;
      }
      os.close();
      is.close();
      socket.close();

不过对里边的对象还是不知道怎么用.也不知道is怎么清空,暑假中要好好从基础学起,今天主要是培养兴趣,哈哈

  兴趣是最好的老师吗!

0 0

相关博文

我的热门文章

img
取 消
img