I need to save a file in spring boot and i can access it in production build also. So where i can store that file?
What is code for getting path , Now i am creating file in pom.xml file location
CodePudding user response:
You can define your destination yourself:
One possible option:
FileOutputStream out;
String filePath = "your destination";
try {
out = new FileOutputStream(filePath);
out.write(someFile.getBytes());
out.close();
} catch (IOException e) {
e.printStackTrace();
}
And later access it by path
CodePudding user response:
You can store a file anywhere in Spring Boot like the previous answer indicated. However to make it easily accessible in production, it is recommended to save it in the src/main/resources folder since that will copy it into the target folder after the build is completed and you can access it just by mentioning it's relative path in your code, rather than using it's entire file path.