gpt4 book ai didi

java - 在静态初始化程序中抑制 FindBugs 警告

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:49 26 4
gpt4 key购买 nike

我有一个静态初始化程序,我正在其中创建一个新的 File 对象。当我将名称传递给它时,由于硬编码的绝对路径,FindBugs 会报告警告。我怎样才能抑制这个警告?

private static final String fileName = "/tmp/m123.txt";
static {
if (new File(fileName).exists()) {
....
}
}

最佳答案

您可以将这个硬编码的文件名移动到属性文件或命令行参数等。

有关属性文件的教程,请参阅此页面 http://www.mkyong.com/java/java-properties-file-examples/

尽管根据 findbugs.sourceforge.net/manual/running.html#commandLineOptions 页面您想要忽略此警告,但您可以使用 -exclude filterFile.xml

关于java - 在静态初始化程序中抑制 FindBugs 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20368896/

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