How to read from particular header in opencsv?

前端 未结 5 2721

I have a csv file. I want to extract particular column from it.For example: Say, I have csv:

id1,caste1,salary,name1
63,Graham,101153.06,Abraham
103,Joseph,12245         


        
5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-20 17:53

    Looking at the javadoc

    if you create a CSVReader object, then you can use the method .readAll to pull the entire file. It returns a List of String[], with each String[] representing a line of the file. So now you have the tokens of each line, and you only want the second element of that, so split them up as they have been nicely given to you with delimiters. And on each line you only want the second element, so:

    public static void main(String[] args){
        String data = "63,Graham,101153.06,Abraham";
        String result[] = data.split(",");
        System.out.print(result[1]);
    }
    

提交回复
热议问题