当前位置:网站首页>File operation serialization recursive copy
File operation serialization recursive copy
2022-07-03 07:10:00 【L gold p】
1、 File
1、1 summary
java.io.File class : Abstract representation of file and file directory paths , It's not about the platform
File It can be built 、 Delete 、 Rename files and directories , but File Can't access the file content itself .
If you need to access the file content itself , You need to use input / Output stream .
Want to be in Java A program that represents a real-life file or directory , Then there must be a File Yes like , however Java One of the procedures File object , There may not be a real file or directory .
File Object can be passed as a parameter to the constructor of the stream
1.2 Construction method
public File(String pathname) With pathname Create... For the path File object , It can be absolute path or relative path , If pathname Is a relative path , The default current path is in the system property user.dir Storage in .
Absolute path : It's a fixed path , Start with the drive
Relative paths : It's about starting from a certain position
public File(String parent,String child) With parent The path of fatherhood ,child Create... For the subpath File object .
public File(File parent,String child) According to a father File Object and sub file path creation File object
1.3 Common methods
Acquisition function :
public String getAbsolutePath(): Get absolute path
public String getPath() : Get path
public String getName() : Get the name
public String getParent(): Get the upper file directory path . If there is no , return null
public long length() : Get file length ( namely : Number of bytes ). Cannot get the length of the directory .
public long lastModified() : Get the last modification time , Millisecond value
public String[] list() : Get the name array of all files or file directories in the specified directory
public File[] listFiles() : Get all the files in the specified directory or file directory File Array
Rename function :
public boolean renameTo(File dest): Rename the file to the specified file path
Judgment function :
public boolean isDirectory(): Determine whether it is a file directory
public boolean isFile() : Determine if it's a document
public boolean exists() : Judge whether it exists
public boolean canRead() : Judge whether it is readable
public boolean canWrite() : Judge whether it is writable
public boolean isHidden() : Determine whether to hide
Create delete function :
public boolean createNewFile() : create a file . If the file exists , Do not create , return false
public boolean mkdir() : Create file directory . If this file directory exists , We won't create . If the upper directory of this file directory does not exist , It doesn't create .
public boolean mkdirs() : Create file directory . If the upper file directory does not exist , Create... Together
matters needing attention : If you create a file or the file directory does not have a drive letter path , that , Default in project Under the path .
public boolean delete(): Delete files or folders
Delete notes :
Java Delete in does not go to the recycle bin .
To delete a file directory , Please note that the file directory cannot contain files or file directories
1.4 Usage mode
1.5 Recursive replication
1 Copy
Is the combination of input and output
2 Get all sub files under the folder
If the sub file is a file , Copy
If the sub file is a directory, then obtain all the sub files of the directory , Do the same thing
Be careful :
When copying , The source directory and destination directory cannot be consistent
2、 Object flow
2.1 summary
2.2 Be careful 
The class to serialize must implement Serializable Interface , This interface is an identifier
This class can be serialized
2、3 serialize
2.4 Deserialization
2.5 serial VersionUID
2.6 Transient
边栏推荐
- Centos切换安装mysql5.7和mysql8.0
- Pat grade a real problem 1166
- Resthighlevelclient gets the mapping of an index
- How to specify the execution order for multiple global exception handling classes
- CentOS php7.3 installing redis extensions
- Troubleshooting of high CPU load but low CPU usage
- Basic teaching of crawler code
- 多个全局异常处理类,怎么规定执行顺序
- [Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
- 万卷书 - 价值投资者指南 [The Education of a Value Investor]
猜你喜欢
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
Win 10 find the port and close the port
Selenium key knowledge explanation
Flask Foundation
Final, override, polymorphism, abstraction, interface
Software testing learning - the next day
[set theory] partition (partition | partition example | partition and equivalence relationship)
【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘
Inno setup production and installation package
MySQL installation
随机推荐
Win 10 find the port and close the port
mongodb
When MySQL inserts Chinese into the database, there is a diamond question mark garbled code
Stream stream
[most detailed] latest and complete redis interview book (50)
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
dataworks自定义函数开发环境搭建
Inno setup production and installation package
Redis command
[Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
多个全局异常处理类,怎么规定执行顺序
10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
[LeetCode]404. Sum of left leaves
dataworks自定義函數開發環境搭建
Liang Ning: 30 lectures on brain map notes for growth thinking
PHP install composer
How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
SecureCRT取消Session记录的密码
Asynchronous programming: async/await in asp Net
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point