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

相關問題