失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java读取配置文件和获得项目根目录

java读取配置文件和获得项目根目录

时间:2024-07-14 20:49:51

相关推荐

java读取配置文件和获得项目根目录

// 相对路径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读取配置文件和获得项目根目录》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。