当前位置:网站首页>Day_ 17 IO stream file class
Day_ 17 IO stream file class
2022-07-05 02:19:00 【Love Siyi alone】
Day_17 Lecture notes
A recursive algorithm
recursive : Progressive regression
The embodiment in the code : Call the method itself inside the method
Cases in life :
Once upon a time there was a mountain , There is a temple in the mountain , There is an old monk in the temple , The old monk tells a story to the young monk ...
Once upon a time there was a mountain , There is a temple in the mountain , There is an old monk in the temple , The old monk tells a story to the young monk ...
Once upon a time there was a mountain , There is a temple in the mountain , There is an old monk in the temple , The old monk tells a story to the young monk ...
Once upon a time there was a mountain , There is a temple in the mountain , There is an old monk in the temple , The old monk tells a story to the young monk ...
Learn programming -> To make money -> Marry a daughter-in-law -> Give birth to a baby ..
Learn programming -> To make money -> Marry a daughter-in-law -> Give birth to a baby ..
Learn programming -> To make money -> Marry a daughter-in-law -> Give birth to a baby ..
Learn programming -> To make money -> Marry a daughter-in-law -> Give birth to a baby ..
Russian Dolls , File traversal
The premise of recursive algorithm
// Find the rules first
1. Methods must be defined
2. There must be an exit
3. The defined method must have formal parameters
4. When calling the method itself inside the method , The parameters passed in should be changed --> Change should go in the direction of Export
5. Don't recurse too many times
Recursive memory graph
The principle of quick sorting
File class
File class : Classes for all files and folders on your computer
Conclusion : There are either files or folders in the computer
File Class constructor and custom constants
*File(String pathname) : Pass in a file / Folder path , Give Way File Object points to the file / Folder ;
File(String parent, String child) : Express in the form of child parent path File object (String Express )
*File(File parent, String child) : Express in the form of child parent path File object ( Parent path File The formal representation of objects )
//File Object creation ,File Only point to files and folders at the end of the path , Does not represent the entire path
File What does object creation do :
1. You create an object
2. Opened up memory space
3. Give Way file Object points to the file at the end of the path / Folder
// File does not exist, no new file was created
File.pathSeparator = ;
File.pathSeparatorChar = ;
File.separator = \
File.separatorChar = \
File Class creation
* boolean createNewFile(): create a file
boolean mkDir(): Create a single level folder
* boolean mkDirs(): Create single level folders or multi-level folders
Relative path and absolute path
// When the files and folders you want to represent are under the project path , You can use relative paths to represent files / Folder path --> Simplify writing
Absolute path : You can definitely find the file / Path to folder --> The full path
characteristic : Start with a drive letter
// Relative paths : Understand references IDEAEclipse The starting point of the relative path of the software : Project
Relative paths : Take the reference as the starting point , Look for files in the path / Folder
characteristic : Don't start with a drive letter
use express delivery :
Absolute path : The earth :\\ Asia \\ China \\ hubei \\ wuhan \\ Jiangxia \\ Maodian Shanzhong road \\ East Lake network Valley \\6 building \\4 floor \\ Silicon Valley \\402\\ Tan bin
Relative paths : // object of reference : East Lake network Valley
6 building \\4 floor \\ Silicon Valley \\402\\ Tan bin
File Class delete function
boolean delete(): Delete file / Folder , Don't go to the recycle bin !!
File Class
* String getName() : get files / Name of the folder
* long length() : Get file size ( Number of bytes taken )
String getAbsolutePath() : Returns... As a string file Object points to the file / Absolute path to folder
File getAbsoluteFile() : With File Object's form return file Object points to the file / Absolute path to folder
String getParent() : Returns... As a string file Object points to the file / The parent path of the folder
File getParentFile() : With File Object's form return file Object points to the file / The parent path of the folder
String getPath() : Get create File Object time , Incoming files / Path to folder (File Class toString Method is called internally getPath)
long lastModified() : obtain File Object points to the file / The last time the folder was modified -> Millisecond value
File Class
* boolean exists() : Judge File Object points to the file / Does the folder exist !!
* boolean isFile() : Judge File Object points to the file / Whether the folder is a file
* boolean isDirectory() : Judge File Object points to the file / Whether the folder is a folder
boolean isAbsolute() : Judgment creation File Object, whether the absolute path is passed in
boolean isHidden() : Judge file Object points to the file / Whether the folder is a hidden file / Folder
Folder traversal function
* File[] listFiles() : Put all the files in a folder / Folder get , Deposit to File[] Array -> Only the current level folder can be obtained
If file Object refers to a file , Then the return value of the method is null --> A null pointer exception occurred
If file Object points to an empty folder , Then the method will return a content of 0 Empty array of -> There will be no null pointer exceptions
* File[] listFiles(FileFilter filter)
FileFilter filter: Folder filter --> Interface
There is and only one abstract method : boolean accept(File file) -> Rewritten is right file Object makes some kind of judgment
If the return value is true, adopt / If the return value is false, Not through
I/O summary
I/O flow technology : Realized Java Data interaction between code and files on hard disk --> Permanent storage of data
I : input -> Input
O : output -> Output
flow : Flow
Find out when to use the input stream / When to use the output stream ? object of reference : At present Java file
Code data ---> In the file : Output stream
The contents of the document ---> In the code : Input stream
I / O Classification of flows :
Flow direction classification : Input and output streams Input/Reader and Output/Writer
File type classification of operation :
Byte file ( All files in the computer are byte files ) : With Stream ending -> Byte stream ;
Character file ( There is a kind of file in byte file , The file is full of characters -> txt,java,xml,html,js,md....) : With Reader/Writer The flow at the end --> Character stream
// How to distinguish character files : use windows The built-in Notepad tool opens without " The statement " The file of is character file
InputStream : Byte input stream
BufferedWriter : Efficient character output stream
OutputStreamWriter : Character output stream -> Converted flow : A stream that converts a byte stream into a character stream
// The essence of character stream is : Byte stream + Coding format
Byte stream architecture
The root node of the byte stream : InputStream/OutputStream -> abstract class
Subclass :
File byte stream ( Normal byte stream ) : FileInputStream/FileOutputStream
Efficient byte stream : BufferedInputStream/BufferedOutputStream
FileOutputStream
FileOutputStream : File byte output stream
Construction method :
FileOutputStream(String name) : The string type path of the incoming file , Let the byte output stream object point to this file ;
FileOutputStream(File file) : Of the incoming file File Type path , Let the byte output stream object point to this file ;
What does the creation of byte output stream object do :
1. You create an object
2. Opened up memory space
3. If the file does not exist, it will help you create the file , If the file exists, a new file will be created to overwrite the original file
4. Let the output stream object point to the file at the end of the path ( Here can only be files )
FileOutputStream How to write data
How to write data : void write -> It's written in bytes
* void write(int b) : Write one byte at a time
void write(byte[] b) : Write an entire byte array at a time
* void write(byte[] b, int off, int len) : Write part of a byte array one at a time
int off -> int startIndex : Starting index
int length -> Write a few
How to write a string ? String -> Byte array
byte[] getBytes()
How to write line breaks ? "\r\n".getBytes()
How to add ? boolean append Add write switch
FileOutputStream(String name, boolean append)
FileOutputStream(File file, boolean append)
FileInputStream
FileInputStream : Normal byte input stream
Construction method : // The file pointed to by the input stream must exist !!
FileInputStream(String name)
FileInputStream(File file)
// The input stream has no additional read
FileInputStream How to read data
How to read data : int read -> Read bytes
* int read() : Read one byte at a time -> The return value is the bytes read
* int read(byte[] b) : Read one byte array at a time
//byte[] b : Used to store data read every time
int read(byte[] b, int off, int len) : Read part of a byte array one at a time
// As long as there is a line break in the file , that read Method can read the newline character
边栏推荐
- Comment mettre en place une équipe technique pour détruire l'entreprise?
- Go RPC call
- Pytorch fine tuning (Fortune): hollowed out design or cheating
- Marubeni Baidu applet detailed configuration tutorial, approved.
- Application and Optimization Practice of redis in vivo push platform
- Rabbit MQ message sending of vertx
- Richview trvunits image display units
- 172. Zero after factorial
- Application and Optimization Practice of redis in vivo push platform
- I use these six code comparison tools
猜你喜欢
Li Kou Jianzhi offer -- binary tree chapter
A label making navigation bar
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
Win: use shadow mode to view the Desktop Session of a remote user
Introduce reflow & repaint, and how to optimize it?
One plus six brushes into Kali nethunter
Security level
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
Interesting practice of robot programming 15- autoavoidobstacles
随机推荐
力扣剑指offer——二叉树篇
100 basic multiple choice questions of C language (with answers) 04
"2022" is a must know web security interview question for job hopping
Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
Visual explanation of Newton iteration method
使用druid连接MySQL数据库报类型错误
[illumination du destin - 38]: Ghost Valley - chapitre 5 Flying clamp - one of the Warnings: There is a kind of killing called "hold Kill"
Asynchronous and promise
CAM Pytorch
Exploration of short text analysis in the field of medical and health (II)
MATLB | multi micro grid and distributed energy trading
Marubeni Baidu applet detailed configuration tutorial, approved.
Leetcode takes out the least number of magic beans
Unified blog writing environment
A label colorful navigation bar
179. Maximum number - sort
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
Use the difference between "Chmod a + X" and "Chmod 755" [closed] - difference between using "Chmod a + X" and "Chmod 755" [closed]
220213c language learning diary