当前位置:网站首页>File class learning
File class learning
2022-06-11 18:04:00 【liaowenxiong】
List of articles
brief introduction
java.io.File Is an abstract representation of the path names of files and directories , Mainly used for the creation of files and directories 、 Search and delete operations
Constant
public static final char separatorChar // This constant holds the system default file name separator , Save as character
public static final String separator // This constant holds the system default file name separator , Save as a string
public static final char pathSeparatorChar // This constant holds the system default path separator , Save as character
public static final String pathSeparator // This constant holds the system default path separator , Save as a string
notes :Windows And the class Unix The file separator of the system is different , So you can't write dead in the project code , It is recommended to use File.separator() Replace .
Common methods
public String getAbsolutePath(); // Access to this File The absolute pathname string for
public String getPath(); // Access to this File Full path name string of
public String toString(); // Access to this File Full path name string of ,toString() Default call getPath()
public String getName(); // Access to this File Represents the name of a file or directory
public long length(); // Access to this File Represents the size of the file , In bytes , Directories have no concept of size , So you can't get the size of the directory
public boolean exists(); // this File Indicates whether the file or directory exists
public boolean isDirectory(); // this File Indicates whether the is a directory
public boolean isFile(); // this File Is it a document
public boolean createNewFile(); // Create this File File represented , When the file with the specified file name does not exist , Will create a new empty file , Otherwise... Will not be created
public boolean delete(); // Delete this File Represents a file or directory
public boolean mkdir(); // Create this File Table of contents , That is, create a single level directory
public boolean mkdirs(); // Create this File Table of contents , If the parent directory does not exist, it will be created together , Create a multi-level directory
public String[] list(); // Traverse this File Indicates the contents of the directory , Will not traverse the contents of subdirectories
public File[] listFiles(); // Traverse this File Indicates the contents of the directory , Will not traverse the contents of subdirectories
Code example
View the system default file separator :
public static void main(String[] args) {
String str = File.pathSeparator;
System.out.println(str); // MacOS The file separator for is a colon ":"
}
Create an empty file :
public static void demo() {
File file = new File("/Users/liaowenxiong/desktop/1.txt"); // The file path name is specified in the constructor
try {
boolean b = file.createNewFile(); // If it is created successfully, it will return true
System.out.println(b);
} catch (IOException e) {
e.printStackTrace();
}
}
边栏推荐
- Spring 2021 daily question [week5 not finished]
- [pat grade B question bank] complete summary
- 光纤熔接知识汇总【转载自微信公众号弱电智能化工程2018】
- Bracket generation ---2022/02/25
- 智能化整体图例,布线、安防、广播会议、电视、楼宇、消防、电气图的图例【转自微信公众号弱电课堂】
- 6-7 file read / write operation
- Codeworks round 479 (Div. 3) [done]
- Summary of clustering methods
- Common shortcut keys for Hello go (x) and GoLand
- Kubernetes deploys elk and collects container logs using filebeat
猜你喜欢

MFSR:一种新的推荐系统多级模糊相似度量

Ffmpeg hardware codec NVIDIA GPU

Chorus translation

【先收藏,早晚用得到】49个Flink高频面试题系列(一)

测试基础之:黑盒测试

Merge two ordered linked lists ---2022/02/24

夜神安装apk,以及bp代理

Network Security Threat Intelligence System

Expérience initiale du moteur de segmentation de l'araignée mariadb
![Winter vacation daily question (improvement group) [end of week 4]](/img/67/89b5164712d8c4eb319b9266dd4b91.jpg)
Winter vacation daily question (improvement group) [end of week 4]
随机推荐
【题解】Codeforces Round #798 (Div. 2)
av_ read_ The return value of frame is -5 input/output error
Comparison of mongoose in express, KOA and egg
任意用户密码重置的10种方式
网络安全威胁情报体系
[practical Script] obtain the line number of a file, and then delete the file content.
Seeing the sudden death of a 28 year old employee, I was silent
Sqli labs customs clearance hey hey~
Tidb GC related problems
测试基础之:黑盒测试
6-1 read string (*) from file
Hello go (XIII). Go language common standard library III
Line up to pick up the express. At this meeting, I sorted out all kinds of code sets
Network Security Threat Intelligence System
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (I)
Rtsp/onvif protocol easynvr video platform arm version cross compilation process and common error handling
adb 命令学习笔记
Tle6389-2g V50's unique pwm/pfm control scheme has a duty cycle of up to 100%, forming a very low differential pressure - keshijin mall
MFSR:一种新的推荐系统多级模糊相似度量
Service学习笔记03- 前台服务实战