title: Formatting a text table with fixed-width columns
body: <p>I have a file with some info of a store and I want to sort it in another file like a table(in Excel).</p>
  
  <p>the file :</p>
  
  <pre><code>001     Tablets                        5      3
  002     pens                           4      1
  005     Computeres                     3      0
  003     Bages                          2      1
  004     USB                            4      0
  </code></pre>
  
  <p>I write this code :</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Sort {
  public static void main(String [] args) throws IOException {
      FileInputStream fileinput = new FileInputStream("input.txt");
      FileOutputStream fileoutput = new FileOutputStream("output.txt");
      Scanner infile = new Scanner(fileinput);
      PrintWriter pw = new PrintWriter(fileoutput);
      int id, quantity, soldQuantity;
      String title;
      pw.println("ID\tTitle\t\t\tQuantity\tSoldQuantity");
      pw.println("");
      while(infile.hasNext()){
          id = infile.nextInt();
          title = infile.next();
          quantity = infile.nextInt();
          soldQuantity = infile.nextInt();
          pw.printf("%6d\t%s\t\t%d\t%d%n", id , title, quantity, soldQuantity);
      }
      infile.close();
      pw.close();
  }
  }
  </code></pre>
  
  <p>and I want it to look like this :</p>
  
  <pre><code>Code(ID)    Name            Quantity    SoldQuantity
  
       001    Tablets                5               3
       002    pens                   4               1
       005    Computeres             3               0
       003    Bages                  2               1
       004    USB                    4               0
  </code></pre>
  
  <p>my problem is the number of the quantity and sold quantity , it don't fit well .
  looks like this :</p>
  
  <pre><code>Code(ID)    Name            Quantity    SoldQuantity
  
       001    Tablets             5               3
       002    pens             4               1
       005    Computers             3               0
       003    Bags             2               1
       004    USB             4               0
  </code></pre>
  
  <p>The problem happens when the size of the name is different if there is a name bigger than "computers" , how can I handle it ?</p>
  
  <p>Thanks  </p>