2010-10-05 48 views
6

我正在写一个来自ant的文本文件的目录路径,稍后由Java应用程序读取它以查找另一个文件。如何使用双反斜线或正斜杠分隔符生成目录路径?

在我的ant脚本我有:

<property name="fulltrainer.dir" location="${trainer.dir}" /> 

<echo file="${trainer.dir}/properties/commonConfig.properties"># KEY   VALUE 
CurrentBuildFile=${fulltrainer.dir}\current_build</echo> 
build.properties文件中trainer.dir

设置为:

trainer.dir=../trainer 

它结束了写作:

# KEY  VALUE 
CurrentBuildFile=C:\Workspaces\ralph\trainer\current_build 

到commonConfig.properties文件。

我需要它来写:

# KEY  VALUE 
CurrentBuildFile=C:\\Workspaces\\ralph\\trainer\\current_build 

,或者我需要它来写:

# KEY  VALUE 
CurrentBuildFile=C:/Workspaces/ralph/trainer/current_build 

我怎么能这样做?

回答

9

这看起来很像这个问题:Ant produces jsfl with backslashes instead of slashes

所以,尽量使用pathconvert任务。

<pathconvert targetos="unix" property="fulltrainer.unix_dir"> 
    <path location="${trainer.dir}"/> 
</pathconvert> 

<property name="cf.props" value="${trainer.dir}/properties/commonConfig.properties"/> 
<echo file="${cf.props}" message="# KEY   VALUE"/> 
<echo file="${cf.props}" append="yes" message="CurrentBuildFile=${fulltrainer.unix_dir}/current_build"/> 
+0

你是如何将源代码格式添加到我的文章的?我似乎无法弄清楚。 – Andy 2010-10-05 20:41:32

+1

我认为它看起来不错 - 当您在降价编辑器中时,您应该可以使用上面的一排按钮,让您可以将格式应用于编辑框中的选定文本。有关信息,请参阅http://stackoverflow.com/editing-help。我希望能够做一个小的编辑来摆脱水平滚动条,但不想改变太多。我向第二个回声添加了“append”属性 - 可能并非必要,但如果没有它,文件将被第二个回声截断。 – 2010-10-05 20:47:01

+0

啊,谢谢你的提示和谢谢你的修复。我从不使用echo来写入文本文件,这样bug就进入了。 – Andy 2010-10-06 02:11:40

相关问题