有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

字符串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”之后

有什么想法吗


共 (2) 个答案

  1. # 1 楼答案

    不,它实际上是生成一个标签——只是你用来查看文件的任何东西都决定通过将标签与某个边界或其他边界对齐来处理标签。如果你把你的postalFB-6666x设为postal我想你会看到一个更大的空间

    这根本不是文件内容的问题

    如果要在列之间强制使用一定数量的空格,则需要写入这么多的空格。或者,使用其他方式查看文件

  2. # 2 楼答案

    Tabstop不是这样工作的。正如wikipedia article所述

    Tab stops are set manually, and pressing the tab key causes the carriage to go to the next tab stop. In text editors on a computer, the same concept is implemented simplistically with automatic, fixed tab stops.

    这意味着tabstop将在文本文件中的预定义位置停止,而不是在插入特定数量的空格所需的空间之后