The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Writing to a file

Posted by Sunil Bhat on January 13, 2001 at 5:26 PM

I am a java starter and am trying to write records to an output text file. I am getting these records into a "resultset" ineterface from a database using JDBC.I want to know how can i do the following thing in java:-

for example say there are two fields per record
one is String Name
other is int ID
what I need to do is that even if the value of String Name is Null i still want to write at least 5 spaces to the output file. Same way even if int ID is null i want to write 3 zeroes into the file. So basically it the question of formatting them.

e.g example1 String Name = "Sunil"
int ID = 1234;

So the output in the text file would be "Sunil1234"

example2 String Name contains Null
int ID = 1234;
So the output file should look like
" 1234"
which means there should be five spaces before 1234


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us