getTempDirectory()
is a FileUtils
class that is used to obtain an instance of the File
class pointing to the system temporary directory.
Refer to this answer to get the absolute path to the system temporary directory.
FileUtils
The definition of FileUtils
can be found in the Apache Commons IO package, which we can add to the Maven project by adding the following dependency to the pom.xml
file:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
For other versions of the
commons-io
package, refer to the Maven Repository.
You can import the FileUtils
class as follows:
import org.apache.commons.io.FileUtils;
public static File getTempDirectory()
The method has no parameters.
This method returns a File
object pointing to the system temporary directory.
import org.apache.commons.io.FileUtils;import java.io.File;public class Main{public static void main(String[] args){File tmpFile = FileUtils.getTempDirectory();System.out.println("The path to the system temporary directory is " + tmpFile.getAbsolutePath());}}
In the code above, we get the File
instance that points to the system temporary directory with the help of the FileUtils.getTempDirectory()
method.
Then, we print the absolute path of the system temporary directory using the instance obtained through the getAbsolutePath()
method.
The output of the code will be as follows:
The path to the system temporary directory is /var/folders/dt/blzdgmcs3vq7hl7ftp997r8w0000gn/T
Free Resources