package ApacheCommonCSV;
import junit.framework.TestCase;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
public class AppTest extends TestCase
{
public void testApp(){
try {
FileReader filereader = new FileReader("/Users/student/Desktop/file.csv");
BufferedReader bufferedReader = new BufferedReader(filereader);
bufferedReader.readLine();
CSVFormat format = CSVFormat.DEFAULT.withDelimiter(',');
CSVParser parser = new CSVParser(bufferedReader, format);
List<CSVRecord> records = parser.getRecords();
for(int i=0;i<records.size();i++){
double[] temp=new double[records.get(i).size()];
for(int j=0;j<records.get(i).size();j++){
temp[j]=Double.parseDouble(records.get(i).get(j));
}
for(int ii=0;ii<temp.length;ii++){
System.out.print(temp[ii]+" ");
}
System.out.println();
}
}catch (Exception e){
System.out.print("please check your upload");
}
}
}
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.5</version>
</dependency>