进阶day08-File中判断的方法
This commit is contained in:
36
javaSE-day08/src/com/inmind/file01/FileDemo04.java
Normal file
36
javaSE-day08/src/com/inmind/file01/FileDemo04.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package com.inmind.file01;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/*
|
||||||
|
File中判断的方法
|
||||||
|
public boolean exists() :此File表示的文件或目录是否实际存在。
|
||||||
|
public boolean isDirectory() :此File表示的是否为目录。
|
||||||
|
public boolean isFile() :此File表示的是否为文件。
|
||||||
|
|
||||||
|
注意:不存在的文件,所有的判断方法都是false
|
||||||
|
*/
|
||||||
|
public class FileDemo04 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
File file = new File("D:/io_test/a1.txt");
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
|
||||||
|
System.out.println(file.exists());//true
|
||||||
|
System.out.println(file.isDirectory());//false
|
||||||
|
System.out.println(file.isFile());//true
|
||||||
|
|
||||||
|
File file1 = new File("D:/io_test");
|
||||||
|
System.out.println(file1.getAbsolutePath());
|
||||||
|
|
||||||
|
System.out.println(file1.exists());//true
|
||||||
|
System.out.println(file1.isDirectory());//true
|
||||||
|
System.out.println(file1.isFile());//false
|
||||||
|
|
||||||
|
File file2 = new File("D:/io_test/b1.txt");
|
||||||
|
System.out.println(file2.getAbsolutePath());
|
||||||
|
|
||||||
|
System.out.println(file2.exists());//true
|
||||||
|
System.out.println(file2.isDirectory());//true
|
||||||
|
System.out.println(file2.isFile());//false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user