您的位置:首页 > 理论基础 > 计算机网络

Java -- 网络编程

2013-11-06 21:46 197 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: