title: Send a string instead of byte through socket in Java
body: <p>How can i send a strin using getOutputStream method. It can only send byte as they mentioned. So far I can send a byte. but not a string value.</p>
  
  <pre><code>public void sendToPort() throws IOException {
  
      Socket socket = null;
      try {
          socket = new Socket("ip address", 4014);
          socket.getOutputStream().write(2); // have to insert the string
      } catch (UnknownHostException e) {
          System.err.print(e);
      } finally {
          socket.close();
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance</p>