读取文件流
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\\