File Separator

This example allows you to build platform-specific paths and directory hierarchies.

File Separator

File Separator

     

This example allows you to build platform-specific paths and directory hierarchies. When you build a path with any of ant's task, Ant is quite happy to convert the separators in to ones appropriate for the operating system on which it is running. Ant will also do the conversion if you pass the string that you have built to its tasks. Therefore, you could rewrite the previous listing. 

 

 

 

 Source code of build.xml:

<project name="FileSeperator" default="echo" basedir=".">

  <target name="echo">

  <echo message="The File name is: ${basedir}${file.separator}build.xml"/>

  <echo message="The directory Path is: ${basedir}${file.separator}build.xml${path.separator}
   ${basedir}${file.separator}build.properties"/>

  </target>

</project>


If the display shows a mixture of file separators, don't disturb ant that is still treating these as strings. The following output will be displayed if you execute ant command on the command prompt.

Download Source Code