您的位置 首页 java

java判断指定文件是否存在的方法介绍

java判断文件是否存在:

/**
     * 判断文件是否存在
     *
     * @Title: isExcite
     * @param @param filePath
     * @param @return
     * @return boolean 返回类型
     * @throws
     */    public static boolean isExcite(String filePath) {
        File file = new File(filePath);
        // 如果文件夹不存在则创建
        if (!file.exists() && !file.isDirectory()) {
            return false;
        } else {
            return true;
        }
    }

exists()

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

抛出:SecurityException如果存在安全管理器,且其SecurityManager.checkRead(java.lang.String)方法拒绝对文件或目录进行写访问。

isDirectory() 这个用来测试该对象存在且是一个目录文件,简单说该对象是一个文件夹,且不是空文件夹就返回true,否则返回false。

更多java知识请关注java基础教程栏目。

文章来源:智云一二三科技

文章标题:java判断指定文件是否存在的方法介绍

文章地址:https://www.zhihuclub.com/20515.shtml

关于作者: 智云科技

热门文章

网站地图