title: How can I create a template for a string?
body: <p>So basically I have a list of java objects that need to be written into a text file with a specific format. </p>
  
  <p>eg. </p>
  
  <pre><code>class car
  {
      String license;
      String color;
      String model;
      String numOfSeats;
  }
  </code></pre>
  
  <p>and this has to be written into a text file where the format of each line is</p>
  
  <p><code>license--color-----model-------numOfSeats------</code></p>
  
  <p>The <code>license</code> must occupy 10 bytes, even if the length of the actual string is less.</p>
  
  <p>The <code>color</code> must occupy 10 bytes, and the <code>model</code> must occupy 12 bytes etc.</p>
  
  <p>So I want to create a template in such a way that I can just plug in the variables, and they occupy the required number of bytes (i.e. padded with spaces if shorter, truncated if longer) </p>
  
  <p>So in the future, if the template changes, I don't need to make any code changes. I would just need to change the template.</p>
  
  <p>I have been exploring JEXL but I am not sure how to achieve this with it.</p>