File
File operations
Create a file
the first method
The first parameter is the directory name, the second parameter is the file name
File file = new file("content", "filename");
file.creatNewFile();
// 若没有该文件则创建该文件并返回true, 若该文件已经存在则返回false。
The second method
The string represents the absolute path of the file
File file = new file("AbsolatePath");
// 获取文件的绝对路径
file.getAbsolatePath();
Determine whether the file exists
file.exists();
// 返回布尔值
Delete Files
file.delete();
// 返回布尔值
View file size
file.length(); //返回值为long
file.available(); // 返回值为int
// 注意文件大小很可能超过类型的最大值
Determine file type
// 判断文件是否为文件
file.isFile();
// 判断文件是否为目录
file.isDirectory();
Folder operation
Create folder object
File dir = new File("绝对路径");
// 遍历操作
for (String name : dir) {
System.out.println(name);
}
Create a directory
File file = new File("绝对路径");
// 创建目录
file.mkdir("绝对路径");
// 创建多级目录
file.mkdirs("绝对路径");