Read one line of a csv file in Java

后端 未结 6 1991
Happy的楠姐
Happy的楠姐 2021-01-21 16:59

I have a csv file that currently has 20 lines of data. The data contains employee info and is in the following format:

first name, last name, Employee ID

So one

6条回答
  •  有刺的猬
    2021-01-21 17:39

    You can do something like this:

    BufferedReader reader = new BufferedReader(new FileReader(<>));
    List lines = new ArrayList<>();
    String line = null;
    while ((line = reader.readLine()) != null) {
        lines.add(line);
    }
    
    System.out.println(lines.get(0));
    

    With BufferedReader you are able to read lines directly. This example reads the file line by line and stores the lines in an array list. You can access the lines after that by using lines.get(lineNumber).

提交回复
热议问题