1. Apache Commons CSV:
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
public class CsvReader {
public static void main(String[] args) {
try (Reader reader = new FileReader("data.csv");
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT)) {
for (CSVRecord csvRecord : csvParser) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
2. OpenCSV:
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import java.io.FileReader;
import java.io.IOException;
public class CsvReader {
public static void main(String[] args) {
try (CSVReader csvReader = new CSVReader(new FileReader("data.csv"))) {
String[] nextRecord;
while ((nextRecord = csvReader.readNext()) != null) {
}
e.printStackTrace();
}
}
}
3. Super CSV:
import org.supercsv.io.CsvListReader;
import org.supercsv.prefs.CsvPreference;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
public class CsvReader {
public static void main(String[] args) {
try (CsvListReader csvReader = new CsvListReader(new FileReader("data.csv"), CsvPreference.STANDARD_PREFERENCE)) {
List<String> csvRecord;
while ((csvRecord = csvReader.read()) != null) {
}
} catch (IOException e) {
e.printStackTrace();
}
}
}