获取相对路径
InputStream fis = null;
try {
ClassPathResource resource = new ClassPathResource("doc" + File.separator + tempName);
fis = resource.getInputStream();
String path = ResourceUtils.getFile("classpath:doc").getAbsolutePath() + File.separator + tempName;
fis = new FileInputStream(new File(path));
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(fis);
}
获取绝对路径
//指定 逆向工程配置文件
String projectPath = ResourceUtils.getFile("classpath:").getAbsolutePath();
projectPath = projectPath.substring(0, projectPath.indexOf("project-name"));
projectPath += "project-name" + File.separator + "src" + File.separator + "main" + File.separator + "resources";
System.out.println("projectPath:" + projectPath);
String filePath = projectPath + File.separator + "xxxx.xml";
System.out.println("filePath:" + filePath);
File configFile = new File(filePath);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);