I am trying to write a Java
code in my Spring MVC Web Application
that will create a file and save the file to a local directory. My code is as follows:
String fileName = new SimpleDateFormat("yyyyMMddHHmmss'.csv'").format(new Date());
File file = new File("C:\\my-files\\"+fileName);
FileWriter writer = new FileWriter(file);
for (Obj obj : objList)
{
StringBuilder sb = new StringBuilder();
sb.append(DATA);
writer.write(sb.toString());
writer.flush();
writer.write("\r\n");
}
writer.close();
This code works for me when I run locally. But when I try to run this code from the server, the file is not getting created. I am not sure if I should be setting some permissions for writing file when the code is run from a server.
I want the file to be created and downloaded to the local drive of the computer from which the web application is accessed. I dont want the file to be saved anywhere else