title: I'm using Drew Noakes's metadata extractor project. Instead of print the output in console,i want to store them in a .txt file.How can i do that?
body: <p>I'm using Drew Noakes's metadata extractor project.When I run the SampleUsage.java, it gives the output in the console. I need to store them in a .txt file, when i do so, I simply lose some of the information, such as, ICC,IPTC information. How can I store them also? </p>
  
  <p>My code is here:</p>
  
  <pre><code>package com.drew.metadata;
  
  import com.drew.imaging.ImageMetadataReader;
  import com.drew.imaging.ImageProcessingException;
  import com.drew.imaging.jpeg.JpegMetadataReader;
  import com.drew.imaging.jpeg.JpegProcessingException;
  import com.drew.imaging.jpeg.JpegSegmentMetadataReader;
  import com.drew.metadata.exif.ExifReader;
  import com.drew.metadata.iptc.IptcReader;
  import java.io.BufferedWriter;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.PrintStream;
  import java.io.PrintWriter;
  import java.io.UnsupportedEncodingException;
  import java.util.Arrays;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  
  
      public static void main(String[] args)
      {
  
  
          File file = new File("Tests/Data/image.jpg");
  
          try {
              Metadata metadata = ImageMetadataReader.readMetadata(file);
  
              print(metadata);
          } catch (ImageProcessingException e) {
  
          } catch (IOException e) {
  
          }
  
          try {
              Metadata metadata = JpegMetadataReader.readMetadata(file);
  
              print(metadata);
          } catch (JpegProcessingException e) {
  
          } catch (IOException e) {
  
          }
  
          try {
  
              Iterable&lt;JpegSegmentMetadataReader&gt; readers = Arrays.asList(new ExifReader(), new IptcReader());
  
              Metadata metadata = JpegMetadataReader.readMetadata(file, readers);
  
              print(metadata);
          } catch (JpegProcessingException e) {
  
          } catch (IOException e) {
  
          }
      }
  
      private static void print(Metadata metadata) throws FileNotFoundException
      {
          PrintStream output = new PrintStream(new File("E:/Project/output.txt"));
           //System.out.println("-------------------------------------");
  
          for (Directory directory : metadata.getDirectories()) {
  
  
              for (Tag tag : directory.getTags()) {
  
              output.println(tag);
             //System.out.println(tag);
  
              }
  
              if (directory.hasErrors()) {
                  for (String error : directory.getErrors()) {
                      System.err.println("ERROR: " + error);
                  }
              }
          }
      output.close();
      }
  }
  </code></pre>
  
  <p>Sample Image:
  <a href="https://i.stack.imgur.com/dpz6g.jpg" rel="nofollow noreferrer">sample image</a></p>
  
  <p>Received Output:</p>
  
  <pre><code>[Exif IFD0] Make - samsung
  [Exif IFD0] Model - SM-G360H
  [Exif IFD0] X Resolution - 72 dots per inch
  [Exif IFD0] Y Resolution - 72 dots per inch
  [Exif IFD0] Resolution Unit - Inch
  [Exif IFD0] Software - G360HDDU0ANL3
  [Exif IFD0] Date/Time - 2016:03:19 14:43:43
  [Exif SubIFD] Exposure Time - 1/392 sec
  [Exif SubIFD] F-Number - f/2.6
  [Exif SubIFD] Exposure Program - Program normal
  [Exif SubIFD] ISO Speed Ratings - 50
  [Exif SubIFD] Exif Version - 2.20
  [Exif SubIFD] Date/Time Original - 2016:03:19 14:43:29
  [Exif SubIFD] Date/Time Digitized - 2016:03:19 14:43:29
  [Exif SubIFD] Shutter Speed Value - 1/390 sec
  [Exif SubIFD] Aperture Value - f/2.6
  [Exif SubIFD] Brightness Value - 0
  [Exif SubIFD] Exposure Bias Value - 0 EV
  [Exif SubIFD] White Balance - Unknown
  [Exif SubIFD] Flash - Flash did not fire
  [Exif SubIFD] Focal Length - 3.3 mm
  [Exif SubIFD] Exposure Mode - Auto exposure
  [Exif SubIFD] White Balance Mode - Auto white balance
  [Exif SubIFD] Scene Capture Type - Standard
  [Exif SubIFD] Contrast - None
  [Exif Thumbnail] Compression - JPEG (old-style)
  [Exif Thumbnail] X Resolution - 72 dots per inch
  [Exif Thumbnail] Y Resolution - 72 dots per inch
  [Exif Thumbnail] Resolution Unit - Inch
  [Exif Thumbnail] Thumbnail Offset - 589 bytes
  [Exif Thumbnail] Thumbnail Length - 15961 bytes
  [File] File Name - image.jpg
  [File] File Size - 429252 bytes
  [File] File Modified Date - Sat Mar 19 17:09:40 +06:00 2016
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>[JPEG] Compression Type - Baseline
  [JPEG] Data Precision - 8 bits
  [JPEG] Image Height - 966 pixels
  [JPEG] Image Width - 1288 pixels
  [JPEG] Number of Components - 3
  [JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
  [JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
  [JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
  [Exif IFD0] Make - samsung
  [Exif IFD0] Model - SM-G360H
  [Exif IFD0] X Resolution - 72 dots per inch
  [Exif IFD0] Y Resolution - 72 dots per inch
  [Exif IFD0] Resolution Unit - Inch
  [Exif IFD0] Software - G360HDDU0ANL3
  [Exif IFD0] Date/Time - 2016:03:19 14:43:43
  [Exif SubIFD] Exposure Time - 1/392 sec
  [Exif SubIFD] F-Number - f/2.6
  [Exif SubIFD] Exposure Program - Program normal
  [Exif SubIFD] ISO Speed Ratings - 50
  [Exif SubIFD] Exif Version - 2.20
  [Exif SubIFD] Date/Time Original - 2016:03:19 14:43:29
  [Exif SubIFD] Date/Time Digitized - 2016:03:19 14:43:29
  [Exif SubIFD] Shutter Speed Value - 1/390 sec
  [Exif SubIFD] Aperture Value - f/2.6
  [Exif SubIFD] Brightness Value - 0
  [Exif SubIFD] Exposure Bias Value - 0 EV
  [Exif SubIFD] White Balance - Unknown
  [Exif SubIFD] Flash - Flash did not fire
  [Exif SubIFD] Focal Length - 3.3 mm
  [Exif SubIFD] Exposure Mode - Auto exposure
  [Exif SubIFD] White Balance Mode - Auto white balance
  [Exif SubIFD] Scene Capture Type - Standard
  [Exif SubIFD] Contrast - None
  [Exif Thumbnail] Compression - JPEG (old-style)
  [Exif Thumbnail] X Resolution - 72 dots per inch
  [Exif Thumbnail] Y Resolution - 72 dots per inch
  [Exif Thumbnail] Resolution Unit - Inch
  [Exif Thumbnail] Thumbnail Offset - 589 bytes
  [Exif Thumbnail] Thumbnail Length - 15961 bytes
  [ICC Profile] Profile Size - 3144
  [ICC Profile] CMM Type - Lino
  [ICC Profile] Version - 2.1.0
  [ICC Profile] Class - Display Device
  [ICC Profile] Color space - RGB 
  [ICC Profile] Profile Connection Space - XYZ 
  [ICC Profile] Profile Date/Time - 1998:02:09 06:49:00
  [ICC Profile] Signature - acsp
  [ICC Profile] Primary Platform - Microsoft Corporation
  [ICC Profile] Device manufacturer - IEC 
  [ICC Profile] Device model - sRGB
  [ICC Profile] XYZ values - 0.964 1 0.825
  [ICC Profile] Tag Count - 17
  [ICC Profile] Copyright - Copyright (c) 1998 Hewlett-Packard Company
  [ICC Profile] Profile Description - sRGB IEC61966-2.1
  [ICC Profile] Media White Point - (0.9505, 1, 1.0891)
  [ICC Profile] Media Black Point - (0, 0, 0)
  [ICC Profile] Red Colorant - (0.4361, 0.2225, 0.0139)
  [ICC Profile] Green Colorant - (0.3851, 0.7169, 0.0971)
  [ICC Profile] Blue Colorant - (0.1431, 0.0606, 0.7141)
  [ICC Profile] Device Mfg Description - IEC http://www.iec.ch
  [ICC Profile] Device Model Description - IEC 61966-2.1 Default RGB colour space - sRGB
  [ICC Profile] Viewing Conditions Description - Reference Viewing Condition in IEC61966-2.1
  [ICC Profile] Viewing Conditions - view (0x76696577): 36 bytes
  [ICC Profile] Luminance - (76.0365, 80, 87.1246)
  [ICC Profile] Measurement - 1931 2° Observer, Backing (0, 0, 0), Geometry Unknown, Flare 1%, Illuminant D65
  [IPTC] Coded Character Set - UTF-8
  [IPTC] Enveloped Record Version - 4
  [IPTC] Caption/Abstract - 
  [IPTC] Keywords - about cse#01;&lt;name&gt;      " emam";&lt;friendof&gt;    "sujon";&lt;place&gt;        "kotbar"i;&lt;about&gt;         "sujon";&lt;friendof&gt;      "emam";&lt;description&gt;   "cvc"
  [File] File Name - image.jpg
  [File] File Size - 429252 bytes
  [File] File Modified Date - Sat Mar 19 17:09:40 +06:00 2016
  </code></pre>