当前位置:网站首页>IO stream (file class introduction)
IO stream (file class introduction)
2022-06-30 06:19:00 【Java shaping】
One 、FiLe The use of the class
1. File An object of class , Represents a file or a file directory ( Be commonly called : Folder )
2. File Class declaration in java.io It's a bag
3. File Class involves the creation of files or file directories 、 Delete 、 rename 、 Modification time 、 File size, etc ,
It does not involve writing or reading the contents of the file . If you need to read or write the contents of the file , You have to use Io Flow to complete .
4. explain :
IDEA in :
If unit test method is used to test , The relative path is the current Module Next .
If you use main() test , The relative path is the current Project Next .
Eclipse in :
Whether using unit testing methods or using main() test , Relative paths are all current Project Next .
establish File Class instance 、 Introduce File Methods defined in class :
1. How to create FiLe Class new File(String filepath) File(string parentPath,String childPath) File(File parentFile,string childPath) 2. Relative paths : Compared with a certain path , The path indicated . Absolute path : The path to the file or file directory that contains the drive letter 3. Separator windows:\\ Unix:/ Universal :File.separator
public void test1() {
// Creation method 1 :
File file1 = new File("hello.txt");
File file2 = new File("D:\\software\\idea\\project\\day08");
// Creation mode 2 :
File file3 = new File("D:\\software", "idea\\project");
// Creation method 3 :
File project = new File(file3, "hi.txt");
}public String getAbsoLutePath(): Get absolute path pablic 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 The following two methods apply to the file directory 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
public boolean renameTo(File dest): Rename the file to the specified file path With file1.renameTo(file2) For example : To return to true, requirement file1 There must be ,file2 Can't exist
public void test3(){
File file1 = new File("hello");// Here my file name is hello, Can not write hello.txt
File file2 = new File("D:\\io\\hi.txt");
boolean b = file1.renameTo(file2);
System.out.println(b);
}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 This is usually used first to judge whether it is in public boolean canRead() : Judge whether it is readable public boolean canwrite() : Judge whether it is writable public boolean isHidden() : Determine whether to hide
Create the corresponding file or file directory in the hard disk 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 Delete a file or file directory from the disk public boolean delete(): Delete files or folders Delete notes : Java Delete in does not go to the recycle bin .
边栏推荐
- Basic use of markdown
- DXP copper laying settings
- [ansible series] fundamentals 02 module debug
- MySQL summary
- Master slave synchronization of MySQL database to realize read-write separation
- MySQL 索引
- Static routing job
- Gestion des utilisateurs de la base de données MySQL
- RSA and AES
- Base64 explanation: playing with pictures Base64 encoding
猜你喜欢

Zibll sub theme v6.4.1wordpress open source download_ Crack the original / use it directly / no tutorial required

Master slave synchronization of MySQL database to realize read-write separation

Idea add database

圖像處理7-圖像增强

One sentence introduction to Trojan horse

Multithreading advanced level

Application of redis client list in practice

Image processing 7- image enhancement

Talking about the struct of go

Base64 explanation: playing with pictures Base64 encoding
随机推荐
C language code record
As function memo
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
Talking about the struct of go
【数据库】事务
requests. The difference between session () sending requests and using requests to send requests directly
DOM (document object model) document XML file object model
接口中方法详解
[openstack]-01- basic introduction
ES6扩展运算符(...)
Picture.....
ES6 array traversal and Es5 array traversal
【学习强化学习】总目录
Strlen and sizeof, array length and string length, don't be silly
MySQL summary
飞升:基于中文分词器IK-2种自定义热词分词器构建方式showcase & 排坑showtime
Unable to read file for extraction: gdx64. dll
Detailed description of methods in the interface
关于Glide加载图片模糊不清楚
Docker is equipped with the latest MySQL image