当前位置:网站首页>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
边栏推荐
- Last week's hot review (2.7-2.13)
- Grub 2.12 will be released this year to continue to improve boot security
- Restful Fast Request 2022.2.1发布,支持cURL导入
- [uc/os-iii] chapter 1.2.3.4 understanding RTOS
- Luo Gu Pardon prisoners of war
- Richview trvunits image display units
- Word processing software
- Official announcement! The third cloud native programming challenge is officially launched!
- Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
- Tucson will lose more than $400million in the next year
猜你喜欢

Practical case of SQL optimization: speed up your database

PowerShell:在代理服务器后面使用 PowerShell

Application and Optimization Practice of redis in vivo push platform

Interesting practice of robot programming 15- autoavoidobstacles

"2022" is a must know web security interview question for job hopping

Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)

PowerShell: use PowerShell behind the proxy server

Win: use PowerShell to check the strength of wireless signal

Icu4c 70 source code download and compilation (win10, vs2022)

Win: use shadow mode to view the Desktop Session of a remote user
随机推荐
What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
Tucson will lose more than $400million in the next year
Win: enable and disable USB drives using group policy
. Net starts again happy 20th birthday
Outlook: always prompt for user password
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
[illumination du destin - 38]: Ghost Valley - chapitre 5 Flying clamp - one of the Warnings: There is a kind of killing called "hold Kill"
"2022" is a must know web security interview question for job hopping
[uc/os-iii] chapter 1.2.3.4 understanding RTOS
JVM's responsibility - load and run bytecode
Valentine's Day flirting with girls to force a small way, one can learn
Application and development trend of image recognition technology
Talk about the things that must be paid attention to when interviewing programmers
Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
[机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
I use these six code comparison tools
How to find hot projects in 2022? Dena community project progress follow-up, there is always a dish for you (1)
Restful fast request 2022.2.1 release, support curl import
官宣!第三届云原生编程挑战赛正式启动!
[OpenGL learning notes 8] texture