Here you can find the source of fileExists(File path)
Parameter | Description |
---|---|
path | the whole file path |
public static boolean fileExists(File path)
//package com.java2s; /*//from w w w .jav a 2s .c o m * Copyright (C) 2015 Dieter J Kybelksties * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * @date: 2015-12-16 * @author: Dieter J Kybelksties */ import java.io.File; public class Main { /** * Check whether a file exists. * * @param path the whole file path * @return true, if the file exists, false otherwise */ public static boolean fileExists(File path) { return path != null && path.exists() && !path.isDirectory(); } /** * Check whether a file exists. * * @param pathString the whole file path as string * @return true, if the file exists, false otherwise */ public static boolean fileExists(String pathString) { if (pathString == null) { return false; } File path = new File(pathString); return path.exists() && !path.isDirectory(); } /** * Check whether a path (file or directory) exists. * * @param path the whole path * @return true, if the path exists, false otherwise */ public static boolean exists(File path) { return path != null && path.exists(); } /** * Check whether a path (file or directory) exists. * * @param pathString the whole path as string * @return true, if the path exists, false otherwise */ public static boolean exists(String pathString) { if (pathString == null) { return false; } return new File(pathString).exists(); } }