static File |
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. |
static File |
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. |
void |
deleteOnExit() When the virtual machine is terminated, a request is sent to delete the files or directories represented by this abstract path name. |
Try {<br/> // obtain the current path of the Program <br/> string strdir = system. getproperty ("user. dir "); <br/> // change the path separator <br/> string folderpath = strdir. replace ('//', file. separatorchar); <br/> string filepath = folderpath + file. separatorchar + "josp. TMP "; <br/> file = new file (folderpath); <br/> // create Temp File <br/> file temp = file. createtempfile ("josp ",". TMP ", file); </P> <p> // Delete temp file when program exits. <br /> Temp. deleteonexit (); </P> <p> // write to file. True indicates that write continues at the end, false indicates that the original content is overwritten. <br/> bufferedwriter out = new bufferedwriter (New filewriter (temp, true); <br/> out. write ("astring/N"); <br/> out. write ("aaaaaaaaa/N"); <br/> out. close (); <br/> out = new bufferedwriter (New filewriter (temp, true); <br/> out. write ("astring/N"); <br/> out. write ("aaaaaaaaa/N"); <br/> out. close (); </P> <p> bufferedreader in = new Bufferedreader (New filereader (temp); <br/> string STR; <br/> while (STR = in. Readline ())! = NULL) <br/> system. out. println (STR); <br/> in. close (); </P> <p >}catch (ioexception e) {<br/>}