Donald Ball wrote:
> > A standard trick is to write to a randomly named temp file (in the same
> > directory, usually.) When you've closed that file, rename the temp file
> > to the real file. The rename operation is atomic so you can avoid any
> > other synchronization.
>
> How do you generate a guaranteed unique name for a file, e.g. the Java
> equivalent of gettmpnam?
>
> - donald
In the JDK 1.1.x family, you are on your own here ... the best way would be
to have all code that creates temporary files in a particular directory
funnel through a particular synchronized method. That method can create a
random or serial number based string of some sort, then make sure it is not
already in use before using it as a pathname.
In JDK 1.2 (i.e. Java2), the createTempFile() method was added to
java.io.File to perform this task.
Craig McClanahan
----------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://www.working-dogs.com/>
Problems?: [EMAIL PROTECTED]