Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to a file in a specific format??  RSS feed

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to create a text file in a particular format using java..
for e.g

Labelxxxx Labelyyyy Label zzzzz
detail1 detail11 detail111
detail2 detail22 detail222
............

like a tabular format..

So how i can i do that??


Thanks,
Jignesh
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.io.FileWriter class can be used for writing characters to a file. For each value to print, convert it to a String, determine how many characters that has, and fill it up with spaces until it's as wide as the column it's in. With Java 5 you could also use the sprintf facility for formatted printing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!