When I need unique file names I use date and time stamp plus a random
number.  Then I check it to make sure it does not exist.   The odds of two
instances of a file happening at the same time with the same random number a
fairly low enough.  I have never actually had a duplicate file name but I still
test to make sure.    I must admit my server is not a high traffic server so it
is possible I simply don't see duplicates because the script is not called
often enough.

    Also I should mention that it is CGI in PERL not Jserv.

Ron Burton

"Craig R. McClanahan" wrote:

> 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]



----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://www.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to