Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to align the text in a text file that is getting its data from an xml file  RSS feed

 
priya navaneethan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam having one xml file.I have a java code that parses the xml file and writes it into a text file.the text that is getting stored in the text file is not formatted properly.i have inserted new line in that text file.the output is like this.i want to format it properly.Iam urgently needing this formatting to be done.please help me out.

ID TASK_ID TASK_DESC START_DATE END_DATE STATUS

ABC ABCDEthis2007-02-192007-03-01 active
aaa bbbthat2007-01-282007-03-01 active

please respond.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

I'll guess you're writing text to a mono-font like Courier, maybe viewing it on the Java console.

You'll have to determine the width of each column. I can't help you there. Once you have that, In Java5 and later PrintStream has a printf method that can do length padding as part of the formatting. In Java 4 and earlier, you'll have to pad each column with leading or trailing blanks yourself.

Does that sound right?
 
priya navaneethan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Hi, welcome to the ranch!

I'll guess you're writing text to a mono-font like Courier, maybe viewing it on the Java console.

You'll have to determine the width of each column. I can't help you there. Once you have that, In Java5 and later PrintStream has a printf method that can do length padding as part of the formatting. In Java 4 and earlier, you'll have to pad each column with leading or trailing blanks yourself.

Does that sound right?


Hi,
I thank you firstly for the immediate response.Iam writing the contents to a plain text file.Iam able to see the output properly on the console.but its not properly spaced in the text file only.how can we automatically feed the spaces so that the contents are properly spaced.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copy of this thread.

As far as an answer to your question: you do know that some fonts are "fixed pitch" and some are 'variable pitch', right? In a fixed-pitch font, each character has the same width; in a variable-pitch font, each character has a different width. So if your console is using a fixed-pitch font (Courier, Lucida Console), and your editor is using a variable-pitch font (Times, Arial) then that would explain your observations. So this has nothing to do with Java, really.
 
priya navaneethan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Please don't post the same question to more than one forum. See here for an explanation of why I just deleted the other copy of this thread.

As far as an answer to your question: you do know that some fonts are "fixed pitch" and some are 'variable pitch', right? In a fixed-pitch font, each character has the same width; in a variable-pitch font, each character has a different width. So if your console is using a fixed-pitch font (Courier, Lucida Console), and your editor is using a variable-pitch font (Times, Arial) then that would explain your observations. So this has nothing to do with Java, really.


Iam sorry sir.i wont repeat it sir
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!