aspose file tools*
The moose likes Java in General and the fly likes creating tab delimited file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "creating tab delimited file" Watch "creating tab delimited file" New topic
Author

creating tab delimited file

satya kiran
Ranch Hand

Joined: Nov 07, 2000
Posts: 52
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

Joined: Apr 17, 2003
Posts: 327
How about using \t instead of your tab variable?


Thanks, leo
satya kiran
Ranch Hand

Joined: Nov 07, 2000
Posts: 52
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

Joined: Aug 20, 2001
Posts: 1824

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:


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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.


http://home.arcor.de/hirnstrom/bewerbung
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
\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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: creating tab delimited file