Thinking in java--18th Chapter-java I/O system

Source: Internet
Author: User
Tags stub

There are many classes of Java I/O. We are going to learn the process of I/O Class library evolution. Because, without a historical perspective, we will soon be confused about when to use which classes, and when not to use them.

18.1 File Class
This is called the FilePath Class A little better.

 PackageCom.sdkd.JavaIO;ImportJava.io.File;ImportJava.io.FilenameFilter;ImportJava.util.Arrays;ImportJava.util.regex.Pattern; Public  class dirlist {    /** * @param args * *     Public Static void Main(string[] args) {//TODO auto-generated method stubFile Path =NewFile ("."); String[] list;if(Args.length = =0) {System.out.println ("args. Length = = 0 ");        List = Path.list (); }Else{list = Path.list (NewDirfilter (args[0])); } arrays.sort (list, string.case_insensitive_order); for(String diritem:list)        {System.out.println (Diritem); }}}class Dirfilter implements filenamefilter{PrivatePattern pattern; Public Dirfilter(String regex)    {pattern = Pattern.compile (regex); }@Override     Public Boolean Accept(File dir, String name) {//TODO auto-generated method stub        return false; }}

The example in this book is to use the command line to run arguments so that string "" is not empty. Other references to filtername within the class can be implemented using internal classes.

The file class has a lot of operations, Google itself.

File path = new File("hms.txt");        if(path.exists()){            System.out.println(path.getAbsolutePath());        }else{            path = new File("hms.txt");            System.out.println(path.getAbsolutePath());        }

The first path = new file ("Hms.txt") created here is just a file stream.
The following detection confirms that you are creating a file.

18.2 Inputs and outputs
Flow: It represents a data source object that has the ability to produce data or a receive-side object that has the ability to accept data. The stream masks the details of the processing data in the actual I/O device.

Sometimes we want to create a single stream, but we want to create multiple objects. In fact, this is the Java Decorator mode (in my blog design mode).

18.3
Adding properties and useful interfaces
Or is the decorator mode used here.
(Questions can be asked.)

18.4 Reader and writer
Provides Unicode-compatible and character-oriented I/O functionality.

There is too much behind, but the front is the foundation, but also the point. After understanding the others will certainly not be a problem.

Thinking in java--18th Chapter-java I/O system

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.