前段时间,老大要求把所有的路径都换成配置文件,不是写死在程序里。然后做了个定时任务,定时任务与前台没有交互,获取不到action对象,就连request对象都没获取到(可能是能力问题),后面问老大,老大教了我一招,Mark下。
public class GetPathTest {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
InputStream ra = GetPathTest.class.getResourceAsStream("jdbc.properties");
properties.load(ra);
String path = properties.getProperty("path");
}
}
这样就能不需要action对象和request对象的情况下获取到classes文件夹下的文件了。
比如conf下的jdbc.properties文件