⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlconnectiondemo.java

📁 java scoket通信的源程序
💻 JAVA
字号:
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.Date;

public class URLConnectionDemo 
{
	public static void main(String[] args) 
	{
		try 
		{
			int n;
			//使用指定的URL:"http://www.yahoo.com.cn",来创建URL类对象url
			URL url = new URL("http://www.yahoo.com.cn");
			
			URLConnection urlConn = url.openConnection();
			InputStream in = urlConn.getInputStream();
			
			System.out.println("Date :"+new Date(urlConn.getDate()));
			
			System.out.println("ContentEncoding :"+urlConn.getContentEncoding());
			
			System.out.println("ContentType :"+urlConn.getContentType());
			
			System.out.println("ContentLength :"+urlConn.getContentLength());
			
			System.out.println("The content of \"http://www.yahoo.com.cn\" is:\n");
			while((n = in.read())!=-1)
			{
				char c = (char)n;
				System.out.print(c);
			}
		} 
		catch (MalformedURLException e) {e.printStackTrace();}
		catch (IOException e) {e.printStackTrace();}		
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -