JavaJava Quick Tip: Locating Temporary Files

Java Quick Tip: Locating Temporary Files

When files are being processed in an application, they are typically held in a temporary location. There are times when a developer needs to know the location of these temp files, and, fortunately, Java has a method we can use to learn this location. For example, you may need to clean up these temporary files at a later date or reference them further in the code.

Here is how you locate temp files in Java:


public class TemporaryLocation
	public static void main(String args[])
		TemporaryLocation temporaryLocation = new TemporaryLocation();
	private void proceed()
		String tempLocation = System.getenv("TEMP");
		System.out.println("TEMP location in your system is " + tempLocation);


Running this code will produce the following output – or something similar, depending upon your computer’s settings and configuration:

[[email protected]]# java TemporaryLocation

TEMP location in your system is /var/tmp/

Read more Java programming tutorials.

Latest Posts

Related Stories