Learn to summarize Java input and output streams

Source: Internet
Author: User
Tags create directory

Mind Mapping

Code actual Demo

1  PackageCom.hanqi.io;2 3 ImportJava.io.*;4 5  Public classTest1 {6 7      Public Static voidMain (string[] args) {8         //file Files9         Ten         //Construction Method (file full path + file name) OneFile File =NewFile ("D:\\test1.txt"); A  -         //determine if a file exists -         if(File.exists ()) the         { -System.out.println ("File exists"); -              -System.out.println ("GetAbsolutePath =" +File.getabsolutepath ()); +              -System.out.println ("getParent =" +file.getparent ()); +              ASystem.out.println ("GetName =" +file.getname ()); at              -             //Deleting Files -             //File.delete (); -              -             //Renaming a file -File.renameto (NewFile ("D:/test2.txt")); in              -              to         } +         Else -         { the              *SYSTEM.OUT.PRINTLN ("File does not exist"); $             Panax Notoginseng             //Create a new file -             //Controllable Exception the             Try +             { A                  the file.createnewfile (); +              -System.out.println ("File creation succeeded"); $              $             } -             Catch(IOException e) -             { the                  -System.out.println ("File creation failed");Wuyi                  the e.printstacktrace (); -             } Wu         } -          About      $          -     } -  -}

Create a file

 PackageCom.hanqi.io;ImportJava.io.*; Public classText2 { Public Static voidMain (string[] args) {//Operating DirectoryFile dir =NewFile ("D:/test/test"); if(!dir.exists ()) {            //Create a directory            if(Dir.mkdirs ()) {System.out.println ("Create directory Success"); }            Else{System.out.println ("Failed to create directory"); }} File File=NewFile ("D:/test/test.txt");//specify a specific file        if(File.exists ()) {}Else        {            Try{file.createnewfile (); System.out.println ("Create file succeeded"); }            Catch(IOException e) {e.printstacktrace (); System.out.println ("Failed to create directory"); }                    }    }}

Learn to summarize Java input and output streams

Related Article

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.