[英]how to save created file to path specified in application.properties file in spring boot
I have a method which creates new file after every execution I don't want to hardcode file path in code so I added a new property in application.properties file like我有一个方法可以在每次执行后创建新文件我不想在代码中硬编码文件路径所以我在 application.properties 文件中添加了一个新属性,如
jmeter.jmx.path=D:\\\\PerformanceTesting\\\\JMXFiles\\\\
jmeter.jmx.path=D:\\\\PerformanceTesting\\\\JMXFiles\\\\
and instance variable which holds value like和保存值的实例变量,如
@Value("${jmeter.jmx.path}")
private String jmxPath;
want to get the value of a variable inside method想要获取方法内部变量的值
public void saveAsJmxFile(HashTree projectTree, String fileName) throws IOException {
//TODO
SaveService.saveTree(projectTree, new FileOutputStream(jmxPath+fileName+".jmx"));
}
its not woking for me, but if i hardcode then it i'll work.它不适合我,但如果我硬编码,那么我会工作。
public void saveAsJmxFile(HashTree projectTree, String fileName) throws IOException {
//TODO remove hardcoded jmxPath
SaveService.saveTree(projectTree, new
FileOutputStream("D:\\PerformanceTesting\\JMXFiles\\"+fileName+".jmx"));
}
just make sure that the directory is exist只要确保目录存在
Files.createDirectories(Paths.get(jmxPath));
i'm using java8+ nio here我在这里使用 java8+ nio
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.