集册 Java实例教程 确定文件或目录

确定文件或目录

欢马劈雪     最近更新时间:2020-01-02 10:19:05

424
确定文件或目录

  

import java.io.File;

/*来自 
 时代Java公众号*/

public class Main {

  public static void main(String[] args) {

    File file = new File("C://FileIO");


    boolean isFile = file.isFile();

    if (isFile)

      System.out.println(file.getPath() + " is a file.");

    else

      System.out.println(file.getPath() + " is not a file.");


    boolean isDirectory = file.isDirectory();

    if (isDirectory)

      System.out.println(file.getPath() + " is a directory.");

    
展开阅读全文