提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取InetAddress和默认字符集名称
//package com.nowjava; import java.net.InetAddress;/*N o w J a v a . c o m 提 供*/ import java.net.UnknownHostException; import java.nio.charset.Charset; import java.util.Arrays; public class Main { public static void main(String[] argv) throws Exception { getAddress(); } public static void getAddress() throws UnknownHostException { String defaultCharsetName = Charset.defaultCharset().displayName(); System.out.println("defaultCharsetName:" + defaultCharsetName); InetAddress address = InetAddress.getLocalHost(); System.out.println(address.getHostName()); System.out.println(address.getHostAddress()); /* from n o w j a v a