zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    BZOJ 4010: [HNOI2015]菜肴制作( 贪心 )
    bzoj 1084
    bzoj 2763
    bzoj 1003
    bzoj 1858
    codevs 1296
    cf 438D
    vijos 1083
    codevs 3303
    bzoj 1296
  • 原文地址:https://www.cnblogs.com/cy2268540857/p/13767191.html
Copyright © 2011-2022 走看看