@param filePathString

@return boolean

@throws Exception
@Description: 文件或目录是否存在
@author liaoqiqi
@date 2013-6-13
423900
public static boolean isFileExist(final String filePathString) throws Exception {

        File f = new File(filePathString);
        return f.exists();
    }
497690
public static boolean isFile(Path path, boolean isFollowLinks) {
		if (null == path) {
			return false;
		}
		final LinkOption[] options = isFollowLinks ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS };
		return Files.isRegularFile(path, options);
	}
497392
public function checkPaths()
    {
        $path = Yii::getAlias($this->templatePath, false);

        if (!$path || !is_dir($path)) {
            throw new Exception("The template path \"{$this->templatePath}\" does not exist");
        }
    }
1110000
private static boolean accept(final String extension, final File pathname) {
        if (nulls(extension, pathname)) return false;
        String absPath = pathname.getAbsolutePath();
        final int extLength = extension.length();
        int start = absPath.length() - extLength, end = absPath.length();
        String ext = absPath.substring(start, end);
        if (extension.equalsIgnoreCase(ext)) return true;
        return false;
    }
1051529
static boolean deleteImageFile(String imagePath) {
        // Get the file
        File imageFile = new File(imagePath);

        boolean deleted = false;
        // Delete the image
        if (imageFile.exists()) {
            deleted = imageFile.delete();
        }

        return deleted;
    }
280580
private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException {
        if (isInFileObjectHistory(fileObject, forWriting)) {
            if (lint)
                log.warning("proc.file.reopening", fileObject.getName());
            throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
        }
        if (forWriting)
            fileObjectHistory.add(fileObject);
    }
1208899
@Override
  public boolean isDirectory(final Path f) throws IOException {
    if (stocatorPath.isTemporaryPath(f)) {
      return false;
    }
    final Path path = storageClient.qualify(f);
    try {
      FileStatus fileStatus = getFileStatus(path);
      LOG.debug("is directory: {} : {}", path.toString(), fileStatus.isDirectory());
      return fileStatus.isDirectory();
    } catch (FileNotFoundException e) {
      return false;
    }
  }
510618
public static boolean isFilePath(Object value)
    {
        // nullでないこと
        if (value == null)
        {
            return false;
        }

        // String型であること
        if (String.class.isAssignableFrom(value.getClass()) == false)
        {
            return false;
        }

        // 空文字でないこと
        String valueString = (String) value;
        if (StringUtils.isEmpty(valueString))
        {
            return false;
        }

        return true;
    }
394257
public void setFilePath(String filePath)
    {
        //create a new file
        File fileInstance=null;
        if(filePath!=null)
        {
            fileInstance=new File(filePath);
        }
        
        //set file
        this.setFile(fileInstance);
    }
929135
private static void loadFile(String filePath) {
        final Path path = FileSystems.getDefault().getPath(filePath);

        try {
            data.clear();
            data.load(Files.newBufferedReader(path));
        } catch(IOException e) {
            LOG.warn("Exception while loading " + path.toString(), e);
        }
    }
800420
public static boolean isAbsolutePath (final String path) {
        if (path == null || path.trim().length() == 0) {
            return false;
        }

        if (File.separator.equals(UNIX_SEPARATOR)) {
            return path.startsWith(UNIX_SEPARATOR);
        } else

        if (File.separator.equals(WINDOWS_SEPARATOR) && path.length() > 2) {
            return path.matches("([a-zA-Z]:|\\\\)\\\\.*");
        }

        return false;
    }
1266963
public static String readFileContentToString(String filePath)
            throws IOException {
        String content = "";
        content = Files.toString(new File(filePath), Charsets.UTF_8);
        return content;
    }
376628
def is_in_file_tree(fpath, folder):
    
    file_folder, _ = os.path.split(fpath)
    other_folder = os.path.join(folder, "")
    return other_folder.startswith(file_folder)
631576
public static boolean deleteRecursive(File path) throws FileNotFoundException {
        if (!path.exists()) {
            throw new FileNotFoundException(path.getAbsolutePath());
        }

        boolean success = true;
        if (path.isDirectory()) {
            for (File f : path.listFiles()) {
                success = success && FileUtils.deleteRecursive(f);
            }
        }

        return success && path.delete();
    }
336207
@Override
    public boolean accept(File pathname) {
        try {
            final boolean filesMatched = super.getFilesMatched();
            final boolean accepted = super.accept(pathname);
            if (accepted && filters != null && FileContentSearch.contains(pathname, filters)) {
                if (!filesMatched) {
                    super.setFilesMatched(filesMatched);
                }
                return false;
            }
            return accepted;
        } catch (IOException ex) {
            LOGGER.warn(String.format("Error testing file %s", pathname), ex);
        }
        return false;
    }
812460
public static boolean writeFile(String filePath, String fileContent,
			String encoding) {
		FileOutputStream fout = null;
		FileChannel fcout = null;
		File file = new File(filePath);
		if (file.exists()) {
			file.delete();
		}
		
		try {
			fout = new FileOutputStream(filePath);
			// 获取输出通道
			fcout = fout.getChannel();
			// 创建缓冲区
			// ByteBuffer buffer = ByteBuffer.allocate(1024);
			ByteBuffer buffer = ByteBuffer.wrap(fileContent.getBytes(encoding));
			fcout.write(buffer);
			fout.flush();
		} catch (FileNotFoundException e) {
			LogUtil.writeErrorLog("WriteFile fail", e);
			return false;
		} catch (IOException ex) {
			LogUtil.writeErrorLog("WriteFile fail", ex);
			return false;
		} finally {
			try {
				if (null != fout)
					fout.close();
				if (null != fcout)
					fcout.close();
			} catch (IOException ex) {
				LogUtil.writeErrorLog("Releases any system resources fail", ex);
				return false;
			}
		}
		return true;
	}
1076734
private boolean tryPath(StringBuilder prefix, String el, boolean dir) {
    String path = prefix + "/" + el;

    if (dir && directoryBrowsingDisallowed) {
      path += "/" + xsltdirMarkerName;
    }

    if (debug()) {
      debug("trypath: " + path);
    }

    try {
      URL u = new URL(path);

      URLConnection uc = u.openConnection();

      if (!(uc instanceof HttpURLConnection)) {
        return false;
      }

      HttpURLConnection huc = (HttpURLConnection)uc;

      if (huc.getResponseCode() != 200) {
        return false;
      }

      prefix.append("/");
      prefix.append(el);

      return true;
    } catch (final Throwable t) {
      if (debug()) {
        debug("trypath exception: ");
        error(t);
      }
    }

    return false;
  }