generate functionWed, 22 Mar 2023

How to read a csv file and select a column and record this in java project

import; import java.util.ArrayList; import java.util.Scanner; import; public class CSVReader { void readFile(String fileName){ ArrayList<Integer> list = new ArrayList<>(); try { Scanner inputStream = new Scanner(new File(fileName)); while(inputStream.hasNext()){ String data =; String[] values = data.split(","); list.add(Integer.parseInt(values[2])); } inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println(list); } public static void main(String[] args) { CSVReader obj = new CSVReader(); obj.readFile("C:\\Users\\veera\\Downloads\\befkbhalderstatkode.csv"); } }

Questions about programming?Chat with your personal AI assistant