Skip to content

Instantly share code, notes, and snippets.

@sajith-rahim
Created May 6, 2022 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajith-rahim/e34ed87989502efc38852a5c1e77c27f to your computer and use it in GitHub Desktop.
Save sajith-rahim/e34ed87989502efc38852a5c1e77c27f to your computer and use it in GitHub Desktop.
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;
import java.nio.file.Files;
import java.nio.file.Paths;
public class CSVReader {
private static final String SAMPLE_CSV_FILE_PATH = "./csv-with-header.csv";
public static void main(String[] args) throws IOException {
try (
Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV_FILE_PATH));
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
.withFirstRecordAsHeader()
.withIgnoreHeaderCase()
.withTrim());
) {
/* for (CSVRecord csvRecord : csvParser) {
//csvRecord.getRecordNumber()
//csvRecord.get("ColumnName")
}*/
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment