Java Learning Path (11): IO Stream < foreplay >

Source: Internet
Author: User
Tags stub

Overview of the file class and how to construct
it
Construction Method:
    • File (String pathname): Gets the file object based on a path
    • File (String parent,string child): Gets the file object based on a directory and a sub-file/directory
    • File parent,string Child: Gets the file object based on a parent file object and a sub-file/directory

File should be called a path, path, or folder path.

file refers to the abstract representation of the path name of a document or directory form

Create Features:
    • public boolean CreateNewFile (): Creates a file, and if such a file exists, it is not created
    • public boolean mkdir (): Creates a folder (directory) that is no longer created if such a folder exists
    • public boolean mkdir (): Create folders iteratively, multi-layered folder nesting created
Duplicate name and delete function:
    • public boolean Renameto (file dest): Names the files as specified file paths (as with Linux, the name of the duplicate is actually a paste)
    • public boolean Delete (): Delete files or folders (this deletion is not through the Recycle Bin)
Judging function:
    • public boolean isdirectory (): Determines whether an empty directory
    • public boolean isfile (): Determines whether the file is
    • public Boolean exists (): Determine if there is
    • public boolean CanRead (): Determines whether it is readable
    • public boolean canWrite (): Determines if writable
    • public boolean Ishidden (): Determines whether to hide
Get Features:
    • Public String GetAbsolutePath (): Gets the absolute path
    • Public String GetPath (): Get Path
    • Public String getName (): Get Name
    • public long Length (): Gets the length (number of bytes in the file)
    • Public long LastModified (): Gets the last modified time, millisecond value
    • Public string[] List (): Gets an array of names for all files or folders under the specified directory
    • Public file[] ListFile (): Gets the file array of all files or folders under the specified directory

We implement a file name filter by ourselves

 Packagenull08012133;ImportJava.io.File; Public classDemo01 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubFile File =NewFile ("c:/"); File[] FileList=File.listfiles ();  for(File fileobj:filelist) {if(Fileobj.isfile () &&fileobj.getname (). EndsWith (". Sys")) {System.out.println (Fileobj.getname ()); }        }            }}

Use some of the built-in methods to judge

 Packagenull08012133;ImportJava.io.File;ImportJava.io.FilenameFilter; Public classDemo02 { Public Static voidMain (string[] args) {File file=NewFile ("c:/"); String[] FileNames= File.list (NewFilenameFilter () {@Override Public BooleanAccept (File dir, String name) {//TODO auto-generated Method StubFile f =NewFile (dir,name); returnF.isfile () &&name.endswith (". Sys"));        }        });  for(String filename:filenames) {System.out.println (fileName); }    }    }

Java Learning Path (11): IO Stream < foreplay >

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.