Java -- 网络编程

1. 地址获取  和  编码解码

public class Net {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		InetAddress ip = InetAddress.getByName("127.0.0.1");
		System.out.println("send msg is " + ip.isReachable(5000));
		System.out.println("HostAdd " + ip.getHostAddress() + "HostName " + ip.getHostName() );
		
		InetAddress local = InetAddress.getByAddress(new byte[]{127,0,0,1});
		System.out.println("send msg is " + local.isReachable(5000));
		System.out.println("HostAdd " + local.getHostAddress() + "HostName " + local.getHostName() );
		
		//编码
		String urlStr = URLEncoder.encode("向杰","GBK");
		System.out.println(urlStr);
		//解码
		String keyWord = URLDecoder.decode("%E5%90%91%E6%9D%B0","UTF-8");
		System.out.println(keyWord);
		
	}

}


posted @ 2013-11-06 21:46  今晚打酱油_  阅读(147)  评论(0编辑  收藏  举报