How to Get Temporary File Path in Java


Here this example will explain how to get the temporary file path in Java.

Source Code

package com.beginner.examples;

import java.io.File;
import java.io.IOException;

public class GetTemporaryFilePath {

	public static void main(String[] args) {
		
		try {
			File tmp = File.createTempFile("tmpFile", "txt");
			String tmpFilePath = tmp.getAbsolutePath();
			System.out.println(tmpFilePath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		

	}

}

Output:

C:UsersADMINI~1AppDataLocalTemptmpFile9013274024767517006txt

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments