字符串Java选项卡(“\t”)无法使用FileWriter
正如您所见,在每个文本都有一个选项卡之后,一切都正常工作,但在第三个选项卡(参见输出)之后,它会生成一个空间,而不是选项卡
fileWriter = new FileWriter(indexFile, true);
fileWriter.append(id).append("\t");
fileWriter.append(String.valueOf(idx)).append("\t");
fileWriter.append(String.valueOf(pageCount)).append("\t");
fileWriter.append(postal.toUpperCase()).append("\t"); <-- this one
fileWriter.append(address.toUpperCase());
fileWriter.append("\r\n");
我的输出:
00000347 1 1 FB-6666 DUMMY STREET 1 LAT
问题出现在“FB-6666”之后
有什么想法吗
# 1 楼答案
不,它实际上是生成一个标签——只是你用来查看文件的任何东西都决定通过将标签与某个边界或其他边界对齐来处理标签。如果你把你的
postal
值FB-6666x
设为postal
我想你会看到一个更大的空间这根本不是文件内容的问题
如果要在列之间强制使用一定数量的空格,则需要写入这么多的空格。或者,使用其他方式查看文件
# 2 楼答案
Tabstop不是这样工作的。正如wikipedia article所述
这意味着tabstop将在文本文件中的预定义位置停止,而不是在插入特定数量的空格所需的空间之后