• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writing to Temp files

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've some data coming in the request of a servlet from Flex front end. I've to write code to create a temp folder in my application context and save that data from request to temporary file in this temp folder.
Can anybody guide me on how do i create file names from java code.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class java.io.File has two methods named createTempFile(...).
Have a look at the documentation.
 
Ruchee Goyal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper,
I've named the file by appending the time stamp to a string.
Now my application is deployed in Tomcat server in my sandbox setup & will be deployed in WAS in production.
I need to place these files in some folder say temp in my application root(something like: /webapps/appname/temp). i don't know how doo i point to that location.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you just do something like this:
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ruchee Goyal:
I've named the file by appending the time stamp to a string.



This sort of thing is a bad idea. It works most of the time, but you can easily get occasional errors when two files happen to get created with the same time-stamp. Computers are easily fast enough to process more than one during a particular millisecond.

Use createTempFile() as suggested. If you really can't do that, use a serial number or something like that, but not timestamps.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

What he is actally asking for is a way to create a temporary directory, not a temporary file.

I'm also trying to create a temporary directory for a test case but havn't found any info on that. I have found alot of info on how to create temp files though

Does anyone here know how to create a temporary directory?

Best regards,
Mattias
 
Peter Chase
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In future, please DontWakeTheZombies.

I don't think Java has a facility for making temporary directories.
 
reply
    Bookmark Topic Watch Topic
  • New Topic