title: Convert Properties object to byte array in java
body: <p>I want to convert Properties object to byte[], however i can do with the following piece of code but </p>
  
  <pre><code>private byte[] getBytes(Properties properties){
      StringWriter stringWriter = new StringWriter();
      PrintWriter printWriter=new PrintWriter(stringWriter);
      properties.list(printWriter);
      String fileContent = stringWriter.getBuffer().toString();
      byte[] bytes = fileContent.getBytes();
      try{
          stringWriter.close();
          printWriter.close();
      }catch (IOException e){
          log.error("unable to close resource stringWriter" + e.getStackTrace());
      }
  
      return bytes;
  }
  </code></pre>
  
  <p>but properties.list(printWriter),  will print the string "--listing properties--" string to the console. Need help in finding the best way to do it.</p>