0

I would just read the first line of an file.txt with ANT without using externals libs.

my file is file.txt and his content :

3432424
43545435
756767
345354345
  • You should be able to get there from the information contained here. Its not an exact match but close enough. http://stackoverflow.com/questions/5455309/how-to-read-data-line-by-line-from-a-file-using-ant-script – Neo Nov 14 '16 at 17:03

1 Answers1

3

You can use loadfile ant task to load the file and HeadFilter in filterchain to filter out only the first line of loaded text.

If your text file e.g. test.txt contains the following

abc
def
ghi

then the the target given bellow will print only the first line abc on the console

<target name="read">
    <loadfile property="temp" srcfile="./test.txt">
        <filterchain>
            <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
                <param name="lines" value="1" />
            </filterreader>
        </filterchain>
    </loadfile>
    <echo>${temp}</echo>
</target>
Keshaw Kumar
  • 317
  • 1
  • 4
  • 15