Results 1 to 2 of 2

Thread: Issue:Appending string with leading Zero

  1. #1
    Join Date
    May 2009
    Posts
    21

    Default 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
    1) identifier
    2) date

    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.
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2005
    Posts
    4,231

    Default

    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"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •