File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Get a temporary file name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get a temporary file name" Watch "Get a temporary file name" New topic

Get a temporary file name

Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
I have a Java App that creates a temp file that will be read in by another part of the app at a later stage. I dont want to specify the path, as when the App runs on a different machine, there is no guarantee that the path will be the same ie I dont want to hard code C:\temp\test.txt in the code as C:\ might not exist on the next machine.
Is there anyway around this?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can use the System.getProperty() to get the current working directory then add the path to your file to that.

So much trouble in the world -- Bob Marley
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
You could also check out the createTempFile methods of
I haven't tried it myself but this is an extract from the API:
The default temporary-file directory is specified by the system property On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Win32 systems it is typically "c:\\temp".
I agree. Here's the link:
subject: Get a temporary file name
It's not a secret anymore!