java获取项目classPath路径

来源:互联网 发布:合肥兆度网络怎么样 编辑:程序博客网 时间:2024/05/21 18:48


有时候我们会需要获取java工程中的classPath路径,以下方法可以实现:


Thread.currentThread().getContextClassLoader().getResource("/").getPath()

如果牵涉到跨操作系统,还要进行路径编码:

 URLDecoder.decode(Thread.currentThread().getContextClassLoader().getResource("/").getPath() + CommonsConstans.REDIS_PROPERTIES, "UTF-8");


1 0