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!

The article discusses various Java garbage collection algorithms (Serial, Parallel, CMS, G1, ZGC), their performance impacts, and suitability for applications with large heaps.

The article discusses the Java Virtual Machine (JVM), detailing its role in running Java programs across different platforms. It explains the JVM's internal processes, key components, memory management, garbage collection, and performance optimizatio

Java's Nashorn engine enables JavaScript scripting within Java apps. Key steps include setting up Nashorn, managing scripts, and optimizing performance. Main issues involve security, memory management, and future compatibility due to Nashorn's deprec

Java's try-with-resources simplifies resource management by automatically closing resources like file streams or database connections, improving code readability and maintainability.

Java enums represent fixed sets of values, offering type safety, readability, and additional functionality through custom methods and constructors. They enhance code organization and can be used in switch statements for efficient value handling.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment