Java File class Java.io.File
The Java file class represents the file name and directory pathname in an abstract manner. This class is used primarily for file and directory creation, file lookup, and file deletion.
The file object represents the files and directories that actually exist on the disk. Create a file object by using the following construction method.
- Creates a new file instance with the given parent abstract pathname and subpath name string.
File (file parent, String child);
- Creates a new File instance by converting the given pathname string to an abstract path name.
- Creates a new File instance based on the parent pathname string and the child pathname string.
- Creates a new file instance by converting the given File:uri to an abstract path name.
Directory separators on different platforms are not the same, in order to solve our file class, there is a field
File,separator 与系统有关的默认名称分隔符,为了方便,它被表示为一个字符串
File文件的常用方法:
1.创建
boolean File
createTempFile(String prefix, String suffix, File directory)
Creates a new empty file in the specified directory, using the given prefix and suffix string to generate its name.
2.删除
boolean
delete()
Deletes the file or directory represented by this abstract path name.
void Deleteonexit (); When the program exits, the specified file is deleted.
3.判断
boolean exists()
Tests whether the file or directory represented by this abstract path name exists.
Directory creation directory in Java:
There are two methods in the file class that can be used to create a folder:
- The mkdir () method creates a folder, returns True if successful, and returns False if it fails. Failure indicates that the path specified by the file object already exists, or that the folder cannot be created because the entire path does not yet exist.
- The mkdirs () method creates a folder and all its parent folders.
Recursion: For me. I always feel a bit difficult to understand here. These questions ask me more than I should think about
- function itself to call itself.
- Note: Be sure to specify the end condition when recursion
Practice:
Fibonacci Series: 1,1,2,3,5,8,13 ...
Requirements: Find the value of the specified index position in the series
Realize:
Private Static int fab (int index) { if (index = = 1 | | index = = 2) { return 1; Else { return Fab (index-1) + fab (index-2); } }
The origin of the encoding table
- ? The computer can only recognize binary data, and the early origins are electrical signals.
- In order to facilitate the application of computers, so that it can recognize the language of each country
- The text of each country is represented by numbers, and each one corresponds to form a table.
? This is the code table.
Common coding Tables
- ASCII: US standard Information Interchange code.? The 7 bits of a byte can be represented.
?
- Iso8859-1: Latin Code table. European Code table? Represented by a 8-bit byte.
?
- GB2312: China's Chinese code table.
?
- GBK: China's Chinese Code table upgrade, the integration of more Chinese character symbols.
?
- Unicode: International standard Code, fused with a variety of text. All text is represented in two bytes, and the Java language uses Unicode
?
- UTF-8: A maximum of three bytes to represent one character
Dark Horse Programmer-file Class + recursive simple application