So I'm writing a Java application that uses Simple to store data as xml file, but it is hellishly slow with big files when it stores on a network drive compared to on a local hard drive. So I'd like to store it locally before copying it over to the desired destination.
Is there some smart way to find a temporary local file storage in Java in a system independent way?
E.g. something that returns something such as c:/temp
in windows, /tmp
in linux, and likewise for other platforms (such as mac). I could use application path but the problem is that the Java application is run from the network drive as well.
Temporary Files Location The Temporary Files in Windows are typically found located in two locations: %systemdrive%\Windows\Temp. %userprofile%\AppData\Local\Temp.
The file directory is the directory where the temporary file will be stored. 'NULL' has to be specified for using the default directory.
io. tmpdir is a standard Java system property which is used by the disk-based storage policies. It determines where the JVM writes temporary files, including those written by these storage policies (see Section 4 and Appendix A. 8). The default value is typically " /tmp " on Unix-like platforms.
Temporary files are the type of files that are created to store data temporarily. The programs that users use or Windows itself create these kinds of files.
Try:
String path = System.getProperty("java.io.tmpdir");
See: http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties%28%29
And to add it here for completeness sake, as wic mentioned in his comment, there's also the methods createTempFile(String prefix, String suffix)
and createTempFile(String prefix, String suffix, File directory)
methods from Java's File
class.
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