How to replace template in one file with content of another file?
I have a file username.txt with one word in it.
I have another file with template in it:
<root>
<user name="${usern开发者_开发技巧ame}">
</root>
I need during ant build change template ${username} with content of file username.txt.
How to do it? What ant task should I use for this purpose?If you can make your first file be a properties file instead of containing just the one word e.g.
username=superuser
Then you can load it using the property task. e.g.
<property file="username.properties" />
Update
If the file format needs to remain as in the question then take a look at the LoadFile task. It can be used to load the contents of a file into a property. e.g.
<loadfile property="username" srcFile="username.txt" />
精彩评论