Results 1 to 3 of 3

Thread: should be able to dynamically set the output file name with the timestamp

  1. #1
    Join Date
    Jul 2009
    Posts
    8

    Default should be able to dynamically set the output file name with the timestamp

    Hi,
    I would like to know, how should I be able to dynamically set the output file name with the timestamp and write to a desired destination.

    currently iam hardcoding it like this,

    <beans:bean id="flatFileWriter" class="org.springframework.batch.item.file.FlatFil eItemWriter">
    <beansroperty name="resource" value="file:d:/SAMPLE-200709.txt" />
    <beansroperty name="lineAggregator">
    <beans:bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineAggregator">
    <beansroperty name="delimiter" value=","/>
    </beans:bean>
    </beansroperty>


    I want this file name to be dynamic with my own PREFIX followed by date.(SAMPLE200709.txt)Any ideas................

  2. #2
    Join Date
    Mar 2006
    Posts
    312

    Default

    You can leverage late-binding to take in the output file name as a job parameter and pass it to the writer.

    http://static.springsource.org/sprin...l#late-binding

    Code:
    <property name="resource">
    	<bean class="org.springframework.core.io.FileSystemResource">
    		<constructor-arg value="#{jobParameters[outputFile]}"/>
    	</bean>
    </property>

  3. #3
    Join Date
    Feb 2008
    Posts
    488

    Default

    Alternatively, if you don't want to pass the date as a parameter, you can create a custom Resource implementation that wraps a real Resource but generates the filename at runtime. This is what the former StepExecutionResourceProxy did: https://fisheye.springsource.org/bro...xy.java?r=1778

    P.S. Use CODE tags instead of QUTOE tags for code.

Posting Permissions

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