I am having csv file like below
AccountNumber,reason
1234567890,add
2345678901,dfg
I wrote a code as below for printing all the data from csv file
public CSV(){
public static void main(String[] args){
CSVReader csvreader = new CSVReader ( new FileReader(file name);
List<String> lines = csvreader.readAll();
for(String[] line:lines){
for(int i=0; i<line.length; i ++){
Sop(line[i]);
}
Sop(“/n”);
}
}
}
My requirement is to print the last 6 digits of the first column in csv file
Account number 567890 678901
Can anyone please help me
You can do something like this:
This code snippet reads data from a CSV file using the OpenCSV library, with a focus on custom separators and processing only the first column. The snippet provided below has been modified based on the guide available at https://www.geeksforgeeks.org/reading-csv-file-java-using-opencsv/. For more examples and explanations, please refer to the original guide.
Note:
For large files, it is recommended to use an approach similar to the following:
To respond to your comment, you can check this version that first reads the header row to identify the column names and then searches for the "AccountNumber" column by comparing names. If found, it processes the data in that column.