java网络编程

Posted HarryFish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java网络编程相关的知识,希望对你有一定的参考价值。

package java2;




import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;  
import java.io.FileInputStream;  
import java.io.File;  
import java.net.HttpURLConnection;  
import java.net.URL;
import org.omg.CORBA.portable.InputStream;




public class Net
private static String ENCODE = "GBK";
public static final String GET_URL = "http://www.cngolon.com/request.action?key=j0r56u2";
public static void main(String[] args) throws IOException

long begintime = System.currentTimeMillis();
    URL url = new URL("https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=3174088766,1723506295&fm=80");
    HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
    urlcon.connect();         //获取连接
    java.io.InputStream is = urlcon.getInputStream();
    BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
    StringBuffer bs = new StringBuffer();
    String l = null;
    while((l=buffer.readLine())!=null)
        bs.append(l).append("/n");
   
    System.out.println(bs.toString());
   
    System.out.println(" content-encode:"+urlcon.getContentEncoding());
    System.out.println(" content-length:"+urlcon.getContentLength());
    System.out.println(" content-type:"+urlcon.getContentType());
    System.out.println(" date:"+urlcon.getDate());    
    System.out.println("总共执行时间为:"+(System.currentTimeMillis()-begintime)+"毫秒");

以上是关于java网络编程的主要内容,如果未能解决你的问题,请参考以下文章

Java编程题

java进阶--java网络编程

java 网络编程 为啥采用BufferedReader服务器读不到数据。

java进阶学习 --java网络编程一(转)

Java - 30 Java 网络编程

java socket网络编程