Reading selective column data from a text file into a list in Java

前端 未结 3 1592
栀梦
栀梦 2021-01-02 17:29

Can someone help me to read a selective column of data in a text file into a list..

e.g.: if the text file data is as follows

-------------
id name a         


        
3条回答
  •  余生分开走
    2021-01-02 18:21

    Are the columns delimited by tabs?

    Look at Java CSV, an open source library for reading comma delimited or tab delimited text files. SHould do most of the job. I've never used it myself, but I assume you'd be able to ask for all the values from column 1 (or similar).

    Alternatively, you could read the file one line at a time using a BufferedReader (which has a readLine()) method) and then call String.split() and grab the parts you want.

提交回复
热议问题