Jul 14th, 2009, 08:05 AM
Issue:Appending string with leading Zero
We are using FlatFileItemWriter to write output to a file. Following is the code snippet.
Please find attached code snippet.
Presently we are tring to print two values
In the above example identifier can have at the max 9 character. We have a scenario in which if identifier = 23456. As there are only 5 chars in the example. And 9 chars are reserved for identifier we want output to be printed as 000023456. Means if identifier size < 9, add zero to the leading place.
I tried using value field as name="format" value="%09s (Displayed above), but it is not solving our purpose.
Secondly only flag which is working is (-), apart from this other flags (0,#,+ etc) are not working.
Am i doing something wrong. Please suggest.
Jul 16th, 2009, 10:44 AM
The Javaocs for the Formatter (http://java.sun.com/j2se/1.5.0/docs/...Formatter.html) should help you to understand what to do there. The confusion stems from the fact that "%s" does not accept all flags, in particular leading zeros don't make sense for a String value. Try "%d"?