File f = new File("myfile.txt"); boolean result = f.createNewFile();
This phrase uses the createNewFile() method to create a new file with the filename specified when constructing the File object—in this case, myfile.txt. The createNewFile() method will return a boolean value of true if the file was successfully created and false if the specified filename already exists.
Another method is available in the File class for creating a temporary file: It’s called createTempFile(). This is a static method on the File class. Here, we show how to use this method to create a temporary file:
File tmp = File.createTempFile("temp", "txt", "/temp");
The parameters that we pass to the createTempFile() method are the temp file’s prefix, suffix, ...