如何获取项目中文件的路径

一 文件放在classpath下面

1. 直接获取InputStream

InputStream inputStream = Thread.currentThread()
                .getContextClassLoader().getResourceAsStream("user_table.xml");

2. 获取resource和path

URL resource = Thread.currentThread().getContextClassLoader()
                .getResource("user_table.xml");
        String path = resource.getPath();
原文地址:https://www.cnblogs.com/tangyanbo/p/4283376.html