import java.io.File; import org.apache.commons.io.FileUtils; public class TempDirectoryExample { public static void main(String[] args) { File tempDir = FileUtils.getTempDirectory(); System.out.println("Temporary directory: " + tempDir.getAbsolutePath()); } }
import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; public class TempFileExample { public static void main(String[] args) throws IOException { File tempDir = FileUtils.getTempDirectory(); File tempFile = File.createTempFile("example", ".txt", tempDir); System.out.println("Created temporary file: " + tempFile.getAbsolutePath()); } }In this example, we first retrieve the system's temporary directory using the `getTempDirectory()` function, and then use the `File.createTempFile()` function to create a temporary file in that directory. We specify a prefix of "example", a suffix of ".txt", and the temporary directory as the parent directory for the file. We then print out the absolute path of the temporary file to the console. Overall, the `org.apache.commons.io` package provides a wide range of helpful utility functions for Java developers, and the `FileUtils.getTempDirectory()` function is just one example of the many useful functions in this library.