简体   繁体   中英

Java Reading input from a text file that has multiple columns

This is an example of the text that I need to manipulate:

YEAR (space) MONTH (space) NAME (space)

YEAR (space) MONTH (space) NAME (space)

YEAR (sapce) MONTH (space) NAME (space)

YEAR (sapce) MONTH (space) NAME (space) ...

How would one go about creating an array using only the values in one column? eg the second column (months) or the last column (names)

read each line and split on space, and reformat the array..

read each line and use a substring to add to the array..

read each line and use regular expression..

看一看java.util.Scanner类,特别是hasNext和next方法。

Read this answer . See also the split method of String Class in Java Api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM