Java Is Readable File isReadableFile(File file)

Here you can find the source of isReadableFile(File file)

Description

Check if the passed File point to an existing file and can be read by the user.

License

Open Source License

Parameter

Parameter Description
file file to be checked

Return

true - file point to a file and is readable
false - file is either a directory or is not readable

Declaration

public static boolean isReadableFile(File file) 

Method Source Code


//package com.java2s;
/*/*from w  w  w  .java2  s  .  c o m*/
 * Copyright (C) 2014 suboptimal
 *
 * 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.
 */

import java.io.File;

public class Main {
    /**
     * Check if the passed {@link File} point to an existing file and can be read by the user.
     *
     * @param file file to be checked
     * @return true - <code>file</code> point to a file and is readable<br>
     * false - <code>file</file> is either a directory or is not readable
     */
    public static boolean isReadableFile(File file) {
        boolean state = true;
        if (!file.exists() || !file.isFile()) {
            System.err.println(String.format("%s: does not exist", file.getName()));
            state = false;
        } else if (!file.canRead()) {
            System.err.println(String.format("%s: no read permission", file.getName()));
            state = false;
        }
        return state;
    }
}

Related

  1. isReadable(String filename)
  2. isReadableFile(File f)
  3. isReadableFile(File file)
  4. isReadableFile(File file)
  5. isReadableFile(File file)
  6. isReadableFile(File path)
  7. isReadableFile(final File f)
  8. isReadableFile(final String filename)
  9. isReadableFile(String fileName)