Working on a Java(Spring) based application. I have written a method that saves all the data in a table to a corresponding xls sheet. Right now, I am hard coding the directory location and saving the generated xls there. Is there a way to make it store to the temp location of the user's system. Assuming different file system would have different temp locations.
you can use System.getProperty("java.io.tmpdir")
to get the temporary directory of the environment that is running the application (if you run the application under tomcat you get the tomcat temp folder, if you run the program under the command line you get the folder specified by o.s. environment variable).
If your application is a web one running inside a web container you can append the user name or user id to the file name to distinguish file for different users.
Different properties are defined in System.getProperty(x) as defined here http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#getProperties%28%29
"java.io.tmpdir" Default temp file path user.home
"user.home" User's home directory
"user.dir" User's current working directory
"user.name" User account name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With