项目中用户的资源文件存放的规范配置文件

本文介绍了一个Java工具类SystemConfig,用于从config.properties文件中读取系统配置信息,并提供了获取不同文件类型基本存储路径及URL的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


读取配置文件的:

package com.xuan.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 从<code>config.properties</code>中读取系统配置。
 * @author boss
 */
public final class SystemConfig {

    private static final String CONFIG_FILE = "/config.properties";

    private static final Logger LOG = LoggerFactory.getLogger(SystemConfig.class);

    // 系统配置参数
    private static Properties props;

    private SystemConfig() {
    }

    /**
     * @return 系统配置参数。
     */
    public synchronized static Properties getProperties() {
        if (null != props) {
            return props;
        } else {
            props = new Properties();
            InputStream in = SystemConfig.class.getResourceAsStream(CONFIG_FILE);
            try {
                props.load(in);
            } catch (IOException e) {
                LOG.error("加载系统配置文件'/config.properties'出错。Cause: ", e);
            }
        }
        return props;
    }

    /**
     * @return Blob文件的基本存储路径。
     */
    public static String getBlobDirectory() {
        return getProperties().getProperty("blobDirectory", "/data/ovp/blobs");
    }

    /**
     * @return 图片文件的基本存储路径。
     */
    public static String getImageDirectory() {
        return getProperties().getProperty("imageDirectory", "/data/ovp/images");
    }

    /**
     * @return 音频文件的基本存储路径。
     */
    public static String getAudioDirectory() {
        return getProperties().getProperty("audioDirectory", "/data/ovp/audios");
    }

    /**
     * @return Blob文件访问的基本URL。
     */
    public static String getBlobUrl() {
        return getProperties().getProperty("blobUrl", "http://blobs.videocc.net/blobs/");
    }

    /**
     * @return 图片文件访问的基本URL。
     */
    public static String getImageUrl() {
        return getProperties().getProperty("imageUrl", "http://blobs.videocc.net/images/");
    }

    /**
     * @return 音频文件访问的基本URL。
     */
    public static String getAudioUrl() {
        return getProperties().getProperty("audioUrl", "http://blobs.videocc.net/audios/");
    }
    
    /**
     * @return 图片水印。
     */
    public static String getWatermark() {
        return getProperties().getProperty("watermark", null);
    }
}


文件路径配置文件:

# Project configurations.

# The base directory used for storing blobs.
blobDirectory=${blob.directory}

# The base directory used for storing image files.
imageDirectory=${image.directory}

# The base directory used for storing audio files.
audioDirectory=${audio.directory}


# The base URL prepending blob filename.
blobUrl=http://wxj.videocc.net/wxj/blobs/

# The base URL prepending image filename.
imageUrl=http://wxj.videocc.net/wxj/images/

# The base URL prepending audio filename.
audioUrl=http://wxj.videocc.net/wxj/audios/

# The watermark compoisted to image.
# eg. "/home/workspace/wuxianji/images/logo.png"
watermark=



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值