Basic use of the Java file class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.