How can I use java to determine whether a file with the same name already exists before creating a file?

many answers on the Internet are
File file=new File (path);
if (file.exists ()) {
file.delete ();
}
) first create a file and then determine whether the file exists. Now my question is how to determine whether the file exists on the hard drive before creating a file?

Mar.05,2021

File file=new File(path);

does not create a file, just creates a file object

Menu