title: Read Image Metadata from single file with Java
body: <p>I want to read image metadata from a single file.
  I tried the following code:</p>
  
  <p><a href="http://johnbokma.com/java/obtaining-image-metadata.html" rel="noreferrer">http://johnbokma.com/java/obtaining-image-metadata.html</a>  </p>
  
  <p>When I run it, I get <code>build successful</code> but nothing happens.</p>
  
  <pre><code>public class Metadata {
  
      public static void main(String[] args) {
          Metadata meta = new Metadata();
          int length = args.length;
          for ( int i = 0; i &lt; length; i++ )
          meta.readAndDisplayMetadata( args[i] );
      }
  
      void readAndDisplayMetadata( String fileName ) {
          try {
  
              File file = new File( fileName );
              ImageInputStream iis = ImageIO.createImageInputStream(file);
              Iterator&lt;ImageReader&gt; readers = ImageIO.getImageReaders(iis);
  
              if (readers.hasNext()) {
  
                  // pick the first available ImageReader
                  ImageReader reader = readers.next();
  
                  // attach source to the reader
                  reader.setInput(iis, true);
  
                  // read metadata of first image
                  IIOMetadata metadata = reader.getImageMetadata(0);
  
                  String[] names = metadata.getMetadataFormatNames();
                  int length = names.length;
                  for (int i = 0; i &lt; length; i++) {
                      System.out.println( "Format name: " + names[ i ] );
                      displayMetadata(metadata.getAsTree(names[i]));
                  }
              }
          }
          catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>Please help :)</p>