I'm trying to import CSV files using Java library openCSV. Is there any way to load only specific columns not all of them? My code right now is:
JFileChooser fileopen = new JFileChooser();
FileFilter filter = new FileNameExtensionFilter(
"CSV file", "csv");
fileopen.addChoosableFileFilter(filter);
int ret = fileopen.showDialog(null, "Choose file");
if (ret == JFileChooser.APPROVE_OPTION) {
try {
File file = fileopen.getSelectedFile();
System.out.println("Opening: " + file.getName());
File csvFilename = fileopen.getSelectedFile();
try (CSVReader csvReader = new CSVReader(new FileReader(csvFilename), ',', '\'',11 )) {
String[] row = null;
while((row = csvReader.readNext()) != null) {
System.out.println(row[0]
+ " # " + row[1]
+ " # " + row[2]);
}
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Glass_search.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Glass_search.class.getName()).log(Level.SEVERE, null, ex);
}
}
This file also got headings so maybe this way?