3

As you can see, after every text comes a tab, everything is working fine, but after third tab (see output) it generates a space not a tab.

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");

My output:

00000347    1   1   FB-6666 DUMMY STREET 1 LAT

The problem comes after "FB-6666".

Any ideas on this?

Kefirchiks
  • 280
  • 4
  • 13

3 Answers3

4

No, it really is generating a tab - it's just that whatever you're using to view the file is deciding to handle tabs by aligning them to some boundary or other. If you make your postal value FB-6666x I suspect you'll then see a much larger space.

This isn't a problem with the file content at all.

If you want to enforce a certain number of spaces between columns, you'll need to write that many spaces. Alternatively, something else to view the file...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

Tabstops don't work this way. As the wikipedia article states,

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.

This means the tabstop will stop at a predefined position in the textfile, not after let's say the space it would take to insert a specific amount of spaces.

2

It is writing a tab I promise - to convince yourself of this you should either open the resulting file in a hex editor and look at the value in that position, or add another character to the value before the tab and see how the format of the output changes.

codebox
  • 19,927
  • 9
  • 63
  • 81
  • Thank you! I [checked](http://i.imgur.com/krc2jjU.png) and it generates a [0x09] HEX, which stands for a tab. – Kefirchiks Aug 28 '15 at 08:04
  • @Kefirchiks no problem, please accept one of the answers and upvote those that you found helpful – codebox Aug 28 '15 at 08:06