The following example demonstrates using the createTempFile() method of the File class to create a temporary file:
/* author by w3cschool.cc Main.java */import java.io.*;public class Main { public static void main(String[] args) throws Exception { File temp = File.createTempFile ("pattern", ".suffix"); temp.deleteOnExit(); BufferedWriter out = new BufferedWriter (new FileWriter(temp)); out.write("aString"); System.out.println("临时文件已创建:"); out.close(); }}
The output result of running the above code is:
临时文件已创建:
The above is Java Example - Create the contents of a temporary file. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!