【发布时间】:2012-12-30 23:07:03
【问题描述】:
我有以下代码可以读取 Java 中的制表符分隔文件:
while ((str = in.readLine()) != null) {
if (str.trim().length() == 0) {
continue;
}
String[] values = str.split("\\t");
System.out.println("Printing file content:");
System.out.println("First field" + values[0] + "Next field" + values[1]);
}
但它打印的是 1 而不是文件内容。这里有什么问题? 示例文件中的一行内容如下:
{Amy Grant}{/m/0n8vzn2}{...}
【问题讨论】:
-
你要拆分的字符串文本是什么?
-
周围有很多 TSV 和 CSV 解析器库 - 我强烈建议您使用其中之一,而不是自己滚动。
-
试试
System.out.println(Arrays.asList(values)); -
@EshaGhosh 你确定,文件是制表符分隔的吗?
-
@EshaGhosh 你能告诉我们标签在哪里使用原始问题吗?它们不会出现在评论中。