Java Create files new file (string parameter) with File.createnewfile ()

Source: Internet
Author: User
New File ("E:\\test\\1.txt");//Create a Document object

At this point in the E-drive test directory is empty, did not create a 1.txt file,

File File = new file ("E:\\test\\1.txt"), Boolean res = File.createnewfile (),/* * CreateNewFile () method, creates a new empty file based on the abstract path, Create failed when file exists under abstract path * If there is no 1.txt file in the E:/test directory, the file is created if 1.txt already exists and the file creation fails * If there is no test directory, the exception is thrown directly; */if (!res) System.out.println ("Create failed! "); ElseSystem.out.println (" created successfully! ");

At this point, in the E-drive test directory, generate file 1.test. :

Java Create files new file (string parameter) with File.createnewfile ()

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.