title: how to read a large data of excel file (xlsx) using java
body: <p>This coding is able to read the small data of excel file... but not reading the large data files in excel files.... how to modify the code further?</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.sql.SQLException;
  import java.util.Iterator;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  /**
   *
   * @author Administrator
   */
  public class ReadExcelNdArray {
  
  
      public static void main(String[] args) throws Exception {
          long start = System.currentTimeMillis();
  
          System.out.println("Time taken: " + (System.currentTimeMillis() - start) + " ms");
  
         File myFile = new File("D://Raghulpr/Transaction Data.xlsx");
              FileInputStream fis = new FileInputStream(myFile);
  
              // Finds the workbook instance for XLSX file
              XSSFWorkbook myWorkBook = new XSSFWorkbook (fis);
  
              // Return first sheet from the XLSX workbook
              XSSFSheet mySheet = myWorkBook.getSheetAt(0);
  
              // Get iterator to all the rows in current sheet
              Iterator&lt;Row&gt; rowIterator = mySheet.iterator();
  
              // Traversing over each row of XLSX file
              while (rowIterator.hasNext()) {
                  Row row = rowIterator.next();
  
                  // For each row, iterate through each columns
                  Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
                  while (cellIterator.hasNext()) {
  
                      Cell cell = cellIterator.next();
  
                      switch (cell.getCellType()) {
                      case Cell.CELL_TYPE_STRING:
                          System.out.print(cell.getStringCellValue() + "\t");
                          break;
                      case Cell.CELL_TYPE_NUMERIC:
                          System.out.print(cell.getNumericCellValue() + "\t");
                          break;
                      case Cell.CELL_TYPE_BOOLEAN:
                          System.out.print(cell.getBooleanCellValue() + "\t");
                          break;
                      default :
  
                      }
                  }
                  System.out.println("");
              }
      }      
  }
  </code></pre>
  
  <p>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space</p>
  
  <pre><code>at java.io.ByteArrayOutputStream.&lt;init&gt;(ByteArrayOutputStream.java:77)
  at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource$FakeZipEntry.&lt;init&gt;(ZipInputStreamZipEntrySource.java:121)
  at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.&lt;init&gt;(ZipInputStreamZipEntrySource.java:55)
  at org.apache.poi.openxml4j.opc.ZipPackage.&lt;init&gt;(ZipPackage.java:88)
  at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:272)
  at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
  at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:254)
  at readexcelndarray.ReadExcelNdArray.main(ReadExcelNdArray.java:36)
  </code></pre>