// 相对路径
String relativelyPath=System.getProperty("user.dir");
// 通过类的加载目录获得路径
InputStream in=TestAction.class.getClassLoader().getResourceAsStream("test.txt");
InputStream in=Test1.class.getResourceAsStream("/test.txt");
// 通过servlet获得路径
ServletContext context=this.getServletContext();
// 通过request获得路径
String path=request.getSession().getServletContext().getRealPath("/");
// classpath的获取路径
Thread.currentThread().getContextClassLoader().getResource("").getPath()
DemoController.class.getClassLoader().getResource("").getPath()
// 通过属性文件读取路径
InputStream in = new BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);
Locale locale = Locale.getDefault();
ResourceBundle localResource = ResourceBundle.getBundle("test/propertiesTest");
String value = localResource.getString("test");
java读取配置文件和获得项目根目录
最新推荐文章于 2021-10-21 16:31:35 发布