gpt4 book ai didi

java - 在 Ant 中读取属性值

转载 作者:行者123 更新时间:2023-12-05 00:50:03 24 4
gpt4 key购买 nike

我需要从 Ant 脚本中的文件中读取属性值并去除前几个字符。有问题的属性(property)是

path=file:C:/tmp/templates

此属性存储在一个文件中,我可以通过 ant 脚本访问该文件

<property file="${web.inf.dir}/config.properties"/>

我有两个问题:

  1. 如何从加载的属性文件中读取单个“路径”属性?
  2. 如何从属性值中删除前导“file:”?

最终,我想在 Ant 脚本中访问以下名称-值对:

path=C:/tmp/templates

干杯,唐

最佳答案

在 Ant 1.6 或更高版本中,您可以将 LoadProperties 与嵌套的 FilterChain 一起使用

<loadproperties srcFile="${property.file.name}">
<filterchain>
<tokenfilter>
<containsstring contains="path=file:"/>
<replaceregex pattern="path=file:" replace="path=" flags=""/>
</tokenfilter>
</filterchain>
</loadproperties>

这将导致 path 属性被加载,字符串“file:”被剥离。

未经测试,买者自负...

关于java - 在 Ant 中读取属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/342250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com