Untitled
unknown
plain_text
18 days ago
1.5 kB
5
Indexable
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.util.ArrayList; import java.util.List; public class MultilineCSVReader { public static void main(String[] args) { String csvFile = "path/to/companies_trimmed.csv"; try (Reader reader = new FileReader(csvFile); CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT .withFirstRecordAsHeader() .withIgnoreSurroundingSpaces() .withIgnoreEmptyLines() .withEscape('\\') .withQuote('"') .withAllowMissingColumnNames())) { List<CSVRecord> records = csvParser.getRecords(); for (CSVRecord record : records) { String id = record.get("id"); String name = record.get("name"); String description = record.get("info_description"); // Add other fields as needed System.out.println("ID: " + id); System.out.println("Name: " + name); System.out.println("Description: " + description); System.out.println("-----------------------------"); } } catch (IOException e) { e.printStackTrace(); } } }
Editor is loading...
Leave a Comment