Read Data from CSV using CSVReader

package com.Testing;

import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
import au.com.bytecode.opencsv.CSVReader;
import jxl.read.biff.BiffException;

public class ReadDataUsingCSVReader {
	
	public static WebDriver driver;
	
	
  @SuppressWarnings("resource")
@Test
  public void ReadDatafromXLSL() throws InterruptedException, BiffException, IOException {	  
			  
	  System.out.println("----------------------------ReadDatafromXLSL ----------------------------"+"\n" +"\n");	 	  
	  
	  
	// This will load csv file 
	  CSVReader reader = new CSVReader(new FileReader("D:\\QA\\demo.csv"));
	  
	// this will load content into list
	  List<String[]> li=reader.readAll();
	  System.out.println("Total rows which we have is "+li.size());
	            
	 // create Iterator reference
	  Iterator<String[]>i1= li.iterator();
	    
	 // Iterate all values 
	 while(i1.hasNext()){
	     
	 String[] str=i1.next();
	   
	 System.out.print(" Values are ");
	 
	 for(int i=0;i<str.length;i++)
	{
	 
	   System.out.print(" "+str[i]);
	 
	}
	   System.out.println("   ");
	     
	    
	}
	  
	  
	        
      	  	
      
  }
  
 
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *