Java notes (5)

Source: Internet
Author: User

121 Stream functions can be divided into data Sink Stream (Listener: Memory, pipeline, file) and process Stream
(Processing Stream)
122. Before talking about Java stream classes, let's first talk about how to generate a File object, which is a class unrelated to the stream. File objects can be generated.
Objects related to files (and their paths) or directory structures. Because different systems may have different directory result representations
File can be used for system-independent purposes (using abstract path notation ).
123 File object generation method:
File (String path): converts a String representing a path into an abstract path representation.
File (String parent, String child): parent indicates a directory, child indicates a File, and child cannot be empty.
File (File parent, String child): parent represents the directory of a File object, child represents the File, and child does not
Can be empty
124 File provides some methods to test or check a File object:
Boolean exists (): Returns true if the file or directory exists.
Boolean isDirectory (): Returns true if it is a directory.
File [] listFiles (): obtains the array of File objects under the Directory represented by this object. If this directory is not used, null is returned.
String [] list (): Same as above, but returns a String array
Long length (): obtains the size of the file related to this object. If it does not exist, the return value is 0L.
String toString (): obtains the abstract path representation.
String getParent (): Get the directory part of the abstract path representation (excluding the last part)
String getName (): gets the last part of the abstract path representation.
125 method for changing a File object:
Boolean renameTo (File newName): change the path name represented by the current File object to the path name represented by newName.
. If the change is successful, the return value is true.
Boolean mkdir (): generate a new directory. If the input succeeds, the return value is true.
Boolean mkdirs (): generates a new directory that contains non-existent subdirectories. If the call succeeds, the return value is true.
Boolean delete (): delete the File or directory represented by the current File object. If it is a directory, it must be empty. If successful,
Returns true.
126 listFiles () without parameters will list all file names. Using File [] listFiles (FilenameFilter filter)
Filter some special extensions or file names that contain certain characters. FilenameFilter is an interface that must generate a class to implement it.
Filters file names. This class must replace the unique method accept () of FilenameFilter (). Boolean accept (File dir, String
Name). If true is returned, the currently checked files are included in the returned array of listFiles.

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.