server-config-w.properties存放到src目录下面
upload=d:/upload/
address_index_dir=D:/lucene/addressindex/
extaddress_index_dir=D:/lucene/extaddressindex/
sqxx_index_dir=D:/lucene/sqxxindex/
dic_path=D:/lucene/mmseg4j1.9/data
index_dir=D:/lucene/commonindex/
external_person_index_dir=D:/lucene/extpersonindex/
clientversion={APKVERSIONNAME:\"1.0.1\",VERSIONCODE:\"10\",MAPVERSION:\"2\",CONFIGVERSION:\"3\"}
解析类:ServerConfig.java
package com.hzzy.pqgl.util;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
/**
* 读取属性文件的配置参数
*/
public class ServerConfig {
//private static Logger logger = Logger.getLogger("product run.trns.core.parse.NodeParser");
// 属性配置
private static Properties log = null;
// 单例模式
private static ServerConfig config = null;
// 判断当前系统环境
private static final boolean WINDOWS = System.getProperty("os.name").startsWith("Windows");
// 私有构造
private ServerConfig(){ }
// 单例模式初始化
public static ServerConfig getInstance(){
if(config == null){
config = new ServerConfig();
init();
}
return config;
}
// 初始化函数
private static void init(){
if (log == null){
String configfile = null;
if(WINDOWS)
configfile = "server-config-w.properties";
else
configfile = "server-config-l.properties";
String appPath = FileTool.getAppPath();
File file = new File(appPath);
String appPathParent = file.getParent();
String configPath = appPathParent;
appPath= appPath + File.separator + configfile;
file = new File(appPath);
FileInputStream fis = null;
try{
if (!file.exists()){
System.out.println("配置文件不存在");
System.exit(-1);
}
fis = new FileInputStream(file);
log = new Properties();
log.load(fis);
//conn_driver=test_1
log.setProperty("ConfigPath", configPath);
fis.close();
}
catch(Exception e){
//logger.error("config::init::cann't load log file" + e.getMessage());
System.exit(-1);
}
}
}
public Properties getWorkInfo(){
return log;
}
public String getProperty(String key){
return log.getProperty(key);
}
/*
public synchronized void writeLog(String key, String value) throws Exception{
setProperty(key, value);
try{
save();
}
catch(Exception e){
throw new Exception(e.getMessage());
}
}
*/
/*
private void setProperty(String key, String value){
log.setProperty(key, value);
}
private void save() throws Exception{
FileOutputStream fos = null;
try{
fos = new FileOutputStream(file);
log.store(fos, "");
fos.close();
}
catch(Exception e){
throw new Exception(e.getMessage());
}
}
*/
}
FileDownloadResource.java:调用的类
package com.hzzy.pqgl.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.hzzy.pqgl.service.IFileUpandDownService;
import com.hzzy.pqgl.util.ServerConfig;
@Path("download/{id}")
public class FileDownloadRecource {
private IFileUpandDownService fileUpandLoadService;
public void setFileUpandLoadService(
IFileUpandDownService fileUpandLoadService) {
this.fileUpandLoadService = fileUpandLoadService;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public byte[] download(@PathParam("id") String id) {
// String fileRepository="D:\\upload\\";
// ConfigReader reader = new ConfigReader("configs.xml");
// String fileRepository = reader.getItemValueById("foldername",
// "upload");
String fileRepository = ServerConfig.getInstance().getWorkInfo()
.getProperty("upload");
byte[] b = fileUpandLoadService.downFile(fileRepository, id);
return b;
}
}