search
HomeJavaJavaBaseIntroduction to the method of determining whether a directory exists in java

Introduction to the method of determining whether a directory exists in java

Java method to determine whether a directory exists: (Recommended: java video tutorial)

/**
     * 判断文件夹是否存在
     * @param file
     */
    public void checkDirExists(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                LOG.info("目录存在");
            } else {
                LOG.info("同名文件存在, 不能创建");
            }
        } else {
            LOG.info("目录不存在,创建目录");
            file.mkdir();
        }
    }
}

exists()

public boolean exists() tests whether the file or directory represented by this abstract pathname exists.

Throws: SecurityException if a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies write access to the file or directory.

isDirectory()

isDirectory() in java checks whether an object is a folder. The return value is of type boolean. Returns true if so, false otherwise.

The calling method is: object.isDirectory() without specifying parameters.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Introduction to the method of determining whether a directory exists in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version