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.
Asked
Active
Viewed 2.2k times
6
-
Take a look at: http://stackoverflow.com/a/1924159/32090 – Boris Pavlović Jul 01 '15 at 07:13
-
1I highly doubt this would be possible to write to a user local hard disk using your web application, it would be huge security risk. Why don't you generate xls on your server side and allow users to download? I assumed you are developing web app. – Pradeep Simha Jul 01 '15 at 07:14
-
May be this thread can help you get user home. From there you can derive your folder structure relative to the user home http://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java – Johnson Abraham Jul 01 '15 at 07:14
-
@Simz I got your point. – Forkmohit Jul 01 '15 at 07:25
2 Answers
11
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.
5
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

Danielson
- 2,605
- 2
- 28
- 51