The following example demonstrates using the file.createTempFile() method of the File class to create a file in the specified directory:
/* author by w3cschool.cc Main.java */import java.io.File;public class Main { public static void main(String[] args) throws Exception { File file = null; File dir = new File("C:/"); file = File.createTempFile ("JavaTemp", ".javatemp", dir); System.out.println(file.getPath()); }}
The output result of running the above code is:
C:\JavaTemp37056.javatemp
The above is Java example - Create the content of the file in the specified directory. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!