• File类判断功能的方法


    exists()        测试此抽象路径名表示的文件或目录是否存在。

    isDirectory()    测试此抽象路径名表示的文件是否是一个目录。

    isFile()        测试此抽象路径名表示的文件是否是一个标准文件。

    import java.io.File;
    
    public class Demo04File {
        public static void main(String[] args) {
            //判断路径是否存在
            show01();
            show02();
            show03();
        }
    
        private static void show03() {
            File f1=new File("C:\Users\cy\Desktop\1.jpg");
            File f2=new File("C:\Users\cy\Desktop");
            boolean file1 = f1.isFile();
            boolean file2 = f2.isFile();
            System.out.println(file1);
            System.out.println(file2);
        }
    
        private static void show02() {
            File f1=new File("C:\Users\cy\Desktop\1.jpg");
            File f2=new File("C:\Users\cy\Desktop");
            boolean directory1 = f1.isDirectory();
            boolean directory2 = f2.isDirectory();
            System.out.println(directory1);
            System.out.println(directory2);
        }
    
        private static void show01() {
            File f1=new File("C:\Users\cy\Desktop\1.jpg");
            File f2=new File("C:\Users\cy\Desktop\2.jpg");
            boolean exists1 = f1.exists();
            boolean exists2 = f2.exists();
            System.out.println(exists1);
            System.out.println(exists2);
        }
    }
  • 相关阅读:
    集训队日常训练20180518-DIV1
    集训队日常训练20180513-DIV1
    python类的使用与多文件组织
    性能指标
    python调用.so
    动态链接库的使用
    python读写xml文件
    使用python读取文本中结构化数据
    python画图
    numpy及scipy的使用
  • 原文地址:https://www.cnblogs.com/cy2268540857/p/13767191.html
Copyright © 2020-2023  润新知