title: How to generate a PNG image from a dot file format with Graphviz
body: <p>I have a java class that implements a priority queue. Then I have a class test that generates a graph like this:</p>
  
  <pre><code>digraph G {
  Milan  (0.0)       -&gt;     Turin  (1.2)       
  Milan  (0.0)       -&gt;     Montreal  (7.0)       
  Turin  (1.2)       -&gt;     Paris  (5.8)       
  Turin  (1.2)       -&gt;     Tokyo  (2.2)       
  }
  </code></pre>
  
  <p>This graph is saved in a file called "queue".</p>
  
  <p>Now I wish that this graph was displayed in a PNG image using Graphviz. 
  So the last call of my test files (after you have created and filled the queue with priority) is:</p>
  
  <pre><code>queue.toString("queue");
  </code></pre>
  
  <p>All right. The toString method is the following:</p>
  
  <pre><code>public void toString(String fileDot){
      try {
          FileOutputStream file = new FileOutputStream(fileDot); 
          PrintStream Output = new PrintStream(file); 
          Output.print(this.printQueue()); 
          Output.close(); 
          File f = new File(fileDot); 
          String arg1 = f.getAbsolutePath(); 
          String arg2 = arg1 + ".png"; 
          String[] c = {"dot", "-Tpng", arg1, "-o", arg2};
          Process p = Runtime.getRuntime().exec(c); 
          int err = p.waitFor(); 
      }
      catch(IOException e1) {
          System.out.println(e1);
      }
      catch(InterruptedException e2) {
          System.out.println(e2);
      }
  }
  
  private String printQueue() throws IOException {
      String g = new String("");
      char c = '"';
      g = g.concat("digraph G {\n");
      if(isEmpty()) 
          g = g.concat("    " + "Empty priority queue.");
      else {
          for(int i = 0; i &lt; lastIndex; i++) {
              if(heap[2 * i] != null) { 
                  g = g.concat("" + heap[i].elem + "  (" + heap[i].prior + ")   " + "   " + " -&gt; " + "    " + "" + heap[i * 2].elem + "  (" + heap[i * 2].prior + ")       \n" );
                  if(heap[2 * i + 1] != null) 
                      g = g.concat("" + heap[i].elem + "  (" + heap[i].prior + ")   " + "   " + " -&gt; " + "    " + "" + heap[i * 2 + 1].elem + "  (" + heap[i * 2 + 1].prior + ")       \n" ); 
              } 
          } //end for
      } //end else  
      g = g.concat("}");
      return g;   
  }
  </code></pre>
  
  <p>Why is not generated image .png? Where am I wrong? 
  Of course I installed Graphviz. 
  Thanks</p>