以下是一个示例的类,根据传入的布尔值判断使用哪个路径,并输出结果:

public class MapSycTrainPath {
    private static final String mapSycTrainPathByTest = 'D:/mapSycTrain/';
    private static final String mapSycTrainPathByProd = '/home/mapSycTrain/';

    public static void main(String[] args) {
        boolean isProd = true; // 根据需要设置为 true 或 false
        String path = getPath(isProd);
        System.out.println('路径:' + path);
    }

    private static String getPath(boolean isProd) {
        if (isProd) {
            return mapSycTrainPathByProd;
        } else {
            return mapSycTrainPathByTest;
        }
    }
}

main 方法中,根据需要设置 isProd 的值为 truefalse,然后调用 getPath 方法获取对应的路径,并输出结果。

Java 类方法获取路径:根据环境判断测试或生产路径

原文地址: https://www.cveoy.top/t/topic/Ae0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录