简体   繁体   English

Java从具有多列的文本文件中读取输入

[英]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) 年(sapce)月(空间)名称(空间)

YEAR (sapce) MONTH (space) NAME (space) ... 年(sapce)月(空间)名称(空间)...

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. 另请参见Java Api中String类的split方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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