Home > Java > JavaBase > body text

Introduction to the method of determining whether the specified file exists in java

Release: 2019-12-14 16:08:54
Original
3461 people have browsed it

Introduction to the method of determining whether the specified file exists in java

java determines whether the file exists:

/**
     * 判断文件是否存在
     *
     * @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;
        }
    }
Copy after login

exists()

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

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

isDirectory() This is used to test that the object exists and is a directory file. Simply put, if the object is a folder and it is not an empty folder, it returns true, otherwise it returns false.

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 the specified file exists in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template