selfteaching/How-To-Ask-Questions-The-Smart-Way

Facing Issue while reading data from excel in selenium with Java.

ShivaliGuleria opened this issue · 0 comments

CODE
package DataDrivenTesting;

import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.*;

public class ReadingDataFromExcel {

public static void main(String[] args) throws Exception  {

	File Src = new File("C://Users//JOHN//Desktop//version.xlsx");
	FileInputStream file= new FileInputStream(Src);
	
	XSSFWorkbook workbook = new  XSSFWorkbook(file);  //get the workbook
	 XSSFSheet sheet = workbook.getSheet("Sheet 1");  //Providing the sheet name
	 int rowcount = sheet.getLastRowNum();           //Return the row count
	 int columncount = sheet.getRow(0).getLastCellNum(); //return the cell count
	 
	for(int i=0;i<rowcount;i++) 
	{
	XSSFRow Currentrow= sheet.getRow(i);   //Focused on current row
	for(int j=0;j<columncount;j++)
	{	
		String Value = Currentrow.getCell(j).toString();  //Read value from cell
		System.out.print(" " +Value);
		
	}
       System.out.println();
       workbook.close();
    
}
}}

ERROR
Exception in thread "main" java.lang.NoSuchMethodError: 'byte[] org.apache.commons.io.IOUtils.byteArray(int)'
at org.apache.commons.io.output.AbstractByteArrayOutputStream.needNewBuffer(AbstractByteArrayOutputStream.java:104)
at org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.(UnsynchronizedByteArrayOutputStream.java:51)
at org.apache.poi.util.IOUtils.peekFirstNBytes(IOUtils.java:110)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:209)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:143)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:175)
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:130)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:312)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:47)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:296)
at DataDrivenTesting.ReadingDataFromExcel.main(ReadingDataFromExcel.java:15)