将 08-00-27-DC-4A-9E 存储到 java 中的变量(字节)
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
/*
* Extract each array of mac address and convert it to hexa with the
* following format 08-00-27-DC-4A-9E.
*/
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
}
}
}
如何将与此类似的输出存储 08-00-27-DC-4A-9E
到java中的变量
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
/*
* Extract each array of mac address and convert it to hexa with the
* following format 08-00-27-DC-4A-9E.
*/
for (int i = 0; i < mac.length; i++) {
System.out.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
}
}
}
how to store outputs similar to this 08-00-27-DC-4A-9E
to a variable in java
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西:
Something like:
要将该值存储到变量而不是打印它,您只需声明一个变量并将最后一行更改为:
当前,您正在将其格式化为字符串,但然后将其打印到标准输出而不是存储它。
To store that value to a variable instead of printing it, you can just declare a variable and change the last line to:
Currently, you're formatting it into a string, but then printing it to the standard output instead of storing it.