java安卓获取本机IP与ping IP是否通畅

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);
		
	}

}
https://blog.csdn.net/wang121213145/article/details/126371232
posted @ 2023-09-26 21:54  txwtech  阅读(21)  评论(0编辑  收藏  举报