Createtempfile(String prefix, string suffix)
Create an empty file in the default temporary file directory and use the given prefix and suffix to generate its name.
Createtempfile(String prefix, string suffix, file directory)
Create a new empty file in the specified directory and generate its name using the given prefix and suffix string.
Public voidDeleteonexit();
When the virtual machine is terminated, a request is sent to delete the files or directories represented by this abstract path name. Files (or directories) will be deleted in the reverse order of registration. It is invalid to call this method to delete a file or directory registered as deleted. According to the definition in the Java language specification, the deletion operation is attempted only when the virtual machine is terminated normally.
Once a delete operation is requested, the request cannot be canceled. Therefore, use this method with caution.
Package COM. test; import Java. io. file; import Java. io. fileinputstream; import Java. io. fileoutputstream; import Java. io. ioexception; public class test {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub int B, C; byte [] buffer = new byte [100]; file F = new file ("C: \ test"); file ftemp = NULL; try {ftemp = file. createtempfile ("letter ",". TXT ", f); syste M. out. println ("enter a line of text:"); B = system. in. read (buffer); fileoutputstream writefile = new fileoutputstream (ftemp); writefile. write (buffer, 0, B); fileinputstream in = new fileinputstream (ftemp); fileoutputstream out = new fileoutputstream ("C: \ testline.txt"); While (C = in. read ())! =-1) {out. Write (c);} system. Out. println ("input complete !! "); Writefile. close (); In. close (); out. close ();} catch (ioexception E1) {e1.printstacktrace ();} finally {ftemp. deleteonexit ();}}}