读取配置文件的:
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=