Package Com.soar.file;import Java.io.file;import java.io.IOException; Public classDemo2_filemethod {/ * * A: Create function * public boolean createnewfile (): Create file If such a file exists, do not create a * public boolean mkdir (): Create folder if it exists Such a folder, do not create a * public boolean mkdirs (): Create a folder, if the parent folder does not exist, will help you to create a * B: Case Demo * File class creation function * Note: * If you create a file or folder where you forgot to write the drive path, the default is under Project path. */ Public Static void Main(string[] args) throws IOException {//createnewfile ();File Dir1 =NewFile ("AAA"); System. out. println (Dir1.mkdirs ());//trueFile Dir2 =NewFile ("Bbb.txt");//This is also possible to write, folders can also have a suffixSystem. out. println (Dir2.mkdirs ());//trueFile Dir3 =NewFile ("CCC\\DDD"); System. out. println (Dir3.mkdirs ());//Create multi-level directories (folders)}Private Static void CreateNewFile() throws IOException {File File =NewFile ("Yyy.txt"); System. out. println (File.createnewfile ());//If not created, returns True if none is created, returns falseFile file2 =NewFile ("ZZZ");//Without suffix can also be createdSystem. out. println (File2.createnewfile ());//true}}
files and folders created by code under this project
Basic use of the Java file class