Unable to create temporary file

I use this piece of code to create a temporary file:

String tmpDirectoryOp = System.getProperty("java.io.tmpdir"); File tmpDirectory = new File(tmpDirectoryOp); File fstream = File.createTempFile("tmpDirectory",".flv", tmpDirectory); FileOutputStream fos = new FileOutputStream(fstream); DataOutputStream dos=new DataOutputStream(fos); dos.writeChars("Write something"); fstream.deleteOnExit(); fos.close(); dos.close(); 

But in my project folder there is no tmpDirectory.flv . The write suggestion is in a loop that takes quite a while, so the problem is not that the file was deleted before I could see it.
Any ideas? thanks in advance

+4
source share
4 answers

Creates an empty file in the default temporary files directory , using the specified prefix and suffix to generate its name. Calling this method is equivalent to calling createTempFile (prefix, suffix, null).

You can get a temporary directory for your operating system using

 System.getProperty("java.io.tmpdir"); 

You have executed deleteOnExit()

public void deleteOnExit ()
Requires that the file or directory designated by this abstract blank name be deleted when the virtual machine is shut down. Deletion will be attempted only for the normal termination of the virtual machine, as defined by the Java Language Specification. Once a deletion was requested, it is not possible to cancel the request. This method should be used with worried.

Note: this method should not be used to lock files; as a result, the protocol cannot work reliably. FileLock tools should instead.

+9
source

!! Please close the threads!

 File fstream = File.createTempFile("tmpDirectory",".flv"); FileOutputStream fos = new FileOutputStream(fstream); DataOutputStream dos=new DataOutputStream(fos); dos.writeChars("Write something"); fstream.deleteOnExit(); 

**

 fos.close(); dos.close(); 

**

+5
source

Have you looked at the /tmp folder?

If you want to create a temporary file in the specified folder, you need the 3 param function createTempFile

+4
source

Try resetting and closing the stream.

0
source

All Articles