Announcement Announcement Module
Collapse
No announcement yet.
should be able to dynamically set the output file name with the timestamp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      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.

      Comment

      Working...
      X