aspose file tools*
The moose likes Java in General and the fly likes writing to Temp files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "writing to Temp files" Watch "writing to Temp files" New topic
Author

writing to Temp files

Ruchee Goyal
Greenhorn

Joined: Sep 12, 2006
Posts: 12
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

Joined: Aug 16, 2005
Posts: 14347
    
  22

Class java.io.File has two methods named createTempFile(...).
Have a look at the documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ruchee Goyal
Greenhorn

Joined: Sep 12, 2006
Posts: 12
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

Joined: Aug 16, 2005
Posts: 14347
    
  22

Why don't you just do something like this:
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Mattias Ahlin
Greenhorn

Joined: May 31, 2006
Posts: 11
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


Best regards,<br />Mattias
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
In future, please DontWakeTheZombies.

I don't think Java has a facility for making temporary directories.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing to Temp files