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; } }
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!