当前位置:网站首页>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
边栏推荐
- Exploration of short text analysis in the field of medical and health (I)
- Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
- Flutter 2.10 update details
- Blue bridge - maximum common divisor and minimum common multiple
- Icu4c 70 source code download and compilation (win10, vs2022)
- 使用druid连接MySQL数据库报类型错误
- Application and Optimization Practice of redis in vivo push platform
- Missile interception -- UPC winter vacation training match
- WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
- 85.4% mIOU! NVIDIA: using multi-scale attention for semantic segmentation, the code is open source!
猜你喜欢
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
Yolov5 model training and detection
openresty ngx_lua執行階段
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Bert fine tuning skills experiment
Yolov5 model training and detection
Visual studio 2019 set transparent background (fool teaching)
Practical case of SQL optimization: speed up your database
Interesting practice of robot programming 15- autoavoidobstacles
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
随机推荐
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
February database ranking: how long can Oracle remain the first?
Summary of regularization methods
Missile interception -- UPC winter vacation training match
Which common ports should the server open
Richview trvunits image display units
JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
Why do you understand a16z? Those who prefer Web3.0 Privacy Infrastructure: nym
如何做一个炫酷的墨水屏电子钟?
"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Limited query of common SQL operations
[OpenGL learning notes 8] texture
Codeforces Global Round 19 ABC
Stored procedure and stored function in Oracle
MATLB | multi micro grid and distributed energy trading
Grpc message sending of vertx
The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
Prometheus monitors the correct posture of redis cluster
A label making navigation bar