Javaプログラムを使用してサーバーのhostIdを取得する必要があります。これを行うのに役立つ組み込みのJavaAPIに何かありますか?
lab.com$ hostid
f9y7777j -> How can I get this using java
Javaプログラムを使用してサーバーのhostIdを取得する必要があります。これを行うのに役立つ組み込みのJavaAPIに何かありますか?
lab.com$ hostid
f9y7777j -> How can I get this using java
以下を使用すると、コンソールコマンドを実行して、結果を保存できます。-
ProcessBuilder pb = new ProcessBuilder("hostid");
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
{
// Store returned string here.
}
reader.close();
次のコードを試してください。
System.out.println(java.net.InetAddress.getLocalHost().getHostName());