我有一个简单的程序来查找我的 IP 地址并将其转换为字符串。为什么下面的b[i]
值(int)255
?
public class FirstSocketProgramming {
public static void main (String arg[]){
InetAddress local = null;
try {
local = InetAddress.getLocalHost();
} catch (UnknownHostException e){
System.err.println
("Identity Crisis!");
System.exit(0);
}
byte[] b = local.getAddress();
System.out.println (b.toString());
System.out.println (b.length);
String strAddress="";
for (int i = 0; i < b.length; i++)
strAddress += ((int)255&b[i]) + ".";
System.out.println ("Local = " + strAddress);
}
}