1 2 3 4

读取文件流

controller调用类的方法  

String str = new SysConfig().getTemplatePath();

被调用类

package com.edc.util;

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

public class SysConfig {
/**
* 初始化一个空Document对象返回。
*
* @return a Document
*/
public String getTemplatePath() {
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream("sys.properties");
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
String ServerNumber = p.getProperty("templatepath").toString();
return ServerNumber;

}



public String getSavePath() {
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream("sys.properties");
Properties p = new Properties();
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
String ServerNumber = p.getProperty("savepath").toString();
return ServerNumber;

}

}

 

 

sys.properties文件   路径

templatepath D\:\\apache-tomcat-7.0.59\\webapps\\edc\\template\\
savepath=D\:\\apache-tomcat-7.0.59\\webapps\\edc\\WEB-INF\\jsp\\crf\\

posted @ 2017-03-24 10:16  一缕清风丶  阅读(7)  评论(0编辑  收藏  举报