title: How can I load Computer Directory images in JAVAFX
body: <p>I am trying to load my computer folder images into a wall of thumbnails. I read <a href="http://www.java-forums.org/netbeans/15845-javafx-not-able-read-images.html" rel="noreferrer">on a thread</a> from another forum that <code>ImageView</code> &quot;url&quot; instance variable does not support system paths. I tried with the solution there, but it throws an exception: <code>java.lang.OutOfMemoryError: Java heap space as it keeps reading the file</code>.</p>
  <p>another problem is it keeps giving me warning of using package javafx.ext -&gt; <code>SwingUtils.toFXImage</code> method.</p>
  <p>I have also tried to input the URL like that:</p>
  <pre><code>&quot;file://localhost//Users/USER/Pictures/Camera/test/1.JPG&quot;
  </code></pre>
  <p>I tried to display a number of images, but it always only displays 3 to 4 images.</p>
  <p>I checked with the error function given from <code>ImageView</code>, it does not indicate that the reading of my images encountered an error.</p>
  <p>Are there any alternatives?</p>
  <h3>Code</h3>
  <pre><code>function load() {
      println(&quot;RUNTIME {Runtime.getRuntime().maxMemory()}&quot;);
      System.gc();
      Runtime.getRuntime().freeMemory();
  
      //MAC Folder PATH
      var path: String = &quot;/Users/username/Pictures/camera/test/1.JPG&quot;;;
      var file: File = new File(path);
  
      //http://download.oracle.com/docs/cd/E17802_01/javafx/javafx/1.3/docs/api/javafx.ext.swing/javafx.ext.swing.SwingUtils.html
  
      //public toFXImage(image: java.awt.image.BufferedImage) : Image
      //Creates a JavaFX Image from a BufferedImage.
      img = SwingUtils.toFXImage(ImageIO.read(file));
  }
  </code></pre>