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