【发布时间】:2016-04-14 00:14:13
【问题描述】:
我想编辑文本文件中的统一数据列表,这里是数据示例:
我想格式化数据,使其看起来像这样:
到目前为止,我已经能够通过扫描仪读取每一行和令牌扫描仪,但我不确定如何编辑每个令牌以便
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Data {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new File("PortlandWeather2014.txt"));
int lineNumber = 1;
while(scanner.hasNextLine()){
String line = scanner.nextLine();
Scanner token = new Scanner(line);
while(token.hasNext()){
if (token.hasNext()) {
String tokenS = token.next();
}
lineNumber++;
}
}
}
}
我想将每个标记存储在“tokenS”中,并通过使用 if 语句确定“tokenS”是字符串还是双精度,在第二个 imgur 链接中将其编辑为相应的格式,但我不太确定该怎么做这个。
【问题讨论】:
标签: java string token text-processing