Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating tab delimited file

 
satya kiran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i create a file with tab delimited characters?
for example:
I have String1, String2, String3, String4 and i have to create a file like this.
string1 tab string2 tab string 3 tab string4 carriagereturn
how can i create the file like this.
To be more specific i am reading 6 columns from a table and creating a file with tab delimition between the values and carriage return for each row.
How can i achieve this???
I tried using like this
String tab = " ";
bufferWriter.write (string1+tab+string2+tab+string3+tab+string4)
bufferWriter.newLine(); -----> for carriage return.
The file should be in UTF8.
I searched in the net but could not able to find any related topics...
Thanks in advance for your help
kiran
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using \t instead of your tab variable?
 
satya kiran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...
Even \t is not working..... (means spaces are not same .. some times there will be one space and sometimes three and sometimes more...)
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tab character (ASCII 9) should be interperted by whatever text viewer you are using as moving the following text to begin at the next "tab stop;" on old typewriters, a tab stop was located every five spaces; I think that modern text editors tend to use four spaces (of course, MS Word or the like has adjustable tab stops in the top ruler).
So, when you use a tab, your spacing will come out uneven between words, but the columns should (pretty much) line up:

note that "this" and "of" line up, "is" and "the" line up, etc.
This will not always be the case, however. Sometimes the length of the words can affect how things line up. This makes it tough for a human to read, but it makes no difference to a program (like Excel) that is trying to read the tab-delimited file:
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joel McNary:
on old typewriters, a tab stop was located every five spaces; I think that modern text editors tend to use four spaces (of course, MS Word or the like has adjustable tab stops in the top ruler).

Of course it was eight spaces and therefore serious editors use 8 spaces.
Lamers use 4 or 3 spaces and even 2 spaces have been seen.
Why making use of tabs at all?
The biggest bullshit in this area is, to convert tabs to spaces.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use tab delimited files all the time because I can copy and paste into Excel. Of course that requires a real man's text editor that can edit a file with tab expansion turned OFF so x'09' tab characters get copied into the clipboard! Nothing munges text like Kedit!
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\t does not ensure certain 8 spaces between consecutive words. It just starts the next word at NEXT TAB POSITION.
Next Tab Position = Next (1 + (8*n))th character position from current character position.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic