How to write to a file in Ant

To write the text message to a file in ant, you can use ant target echo, it provides the way to directly append to an existing file or write to the new file.

The below target demostrates how to write the string to a file in ant script

<echo file="myoutput.txt" append="true"/>
   The content to be written to myoutput.txt, the classpath is ${classpath}
<echo/>

If the file myoutput.txt already exists, ant will append the content to this file. If it does not, Ant will create a new one and write the content into it.

Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

*

code

  1. anon

    Here’s the right syntax

    The content to be written to myoutput.txt, the classpath is ${classpath}

    Reply
    1. anon

      The content to be written to myoutput.txt, the classpath is ${classpath}

      Reply
    2. admin author

      What’s the difference on the two statements?

      Reply
  2. anon

    The content to be written to myoutput.txt, the classpath is ${classpath}

    Reply