Java hostname

  private static String getHostname()
  {
    try (BufferedInputStream in = new BufferedInputStream(Runtime.getRuntime().exec("hostname").getInputStream()))
    {
      byte[] b = new byte[256];
      in.read(b, 0, b.length); //guaranteed to read all data before returning
      return new String(b);
    }
    catch (IOException e)
    {
      String message = "Error reading hostname";
      Log.error(message);
      throw new RuntimeException(message, e);
    }
  }

Comments

Popular posts from this blog

Sites, Newsletters, and Blogs

Oracle JDBC ReadTimeout QueryTimeout