Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing to Temp files

 
Ruchee Goyal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just do something like this:
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • 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.
 
Mattias Ahlin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In future, please DontWakeTheZombies.

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