In perl we use <FileDescriptor>
to read data line by ilne from a file. How to do the same using ant script.
You can do that using the loadfile
task in combination with the for
task from ant-contrib (you will have to download and install ant-contrib).
<project name="test" default="compile">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="path/to/ant-contrib.jar"/>
</classpath>
</taskdef>
<loadfile property="file" srcfile="somefile.txt"/>
<target name="compile">
<for param="line" list="${file}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
</sequential>
</for>
</target>
</project>
Just had to do that myself, actually the for + line.separator solution is flawed because :
Here is another (better) solution based on the previous example :
<project name="test" default="compile">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="path/to/ant-contrib.jar"/>
</classpath>
</taskdef>
<loadfile property="file" srcfile="somefile.txt"/>
<target name="compile">
<for param="line">
<tokens>
<file file="${file}"/>
</tokens>
<sequential>
<echo>@{line}</echo>
</sequential>
</for>
</target>
</project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With