title: Tiff File Compression in java
body: <p>How to compress the tiff file in java, when i am adding the jpeg files to tiff ,the file size was increasing</p>
  
  <p>File f2 = new File("D:/KYCDATA/mani/myimage_compressed.jpeg");</p>
  
  <pre><code>    BufferedImage image3 = ImageIO.read(f2);
      List&lt;BufferedImage&gt; list = new ArrayList&lt;BufferedImage&gt;();
      list.add(image3);
  
      File tiffFile = new File("D:/KYCDATA/mani/mani.tiff");
      if(tiffFile.exists()) {
          tiffFile.delete();
      }
      ImageOutputStream ios = null;
      ImageWriter writer = null;
      Iterator it = ImageIO.getImageWritersByFormatName("tiff");
      if (it.hasNext()) {
          writer = (ImageWriter) it.next();
      }
  
      ios = ImageIO.createImageOutputStream(tiffFile);
      writer.setOutput(ios);
  
      IIOImage iioImage = null;
      for (int i = 0; i &lt; list.size(); i++) {
          iioImage = new IIOImage(list.get(i), null, null);
          if (i == 0) {
              writer.write(iioImage);
          } else {
              writer.writeInsert(i, iioImage, null);
          }
          writer.endWriteSequence();
  </code></pre>