Details of this blog Java.io.File In the class library createNewFile() method
public class CreateNewFileTest { public staticvoid main(String[] args) { File
f = null; boolean bool = false; try { f =new File("study.txt"); bool =
f.createNewFile(); System.out.println("file Exist?" +bool); bool = f.delete();
System.out.println("file Exist?" +bool); bool = f.exists();
System.out.println("file Exist?" +bool); } catch (IOExceptione) {
e.printStackTrace(); } } }
output :
file Exist?true
file Exist?true
file Exist?false
analysis :
File file = new File("xx"); Represents a file under a path
createNewFile() return boolean, Indicates whether the file was created successfully
file.delete() return boolean, Indicates that the file was deleted successfully
f.exists() return boolean, Indicates whether the file exists
Technology
Daily Recommendation