Skip to content

Commit 1d23b7a

Browse files
committed
add FileUtil class
1 parent 616cf62 commit 1d23b7a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2014 suboptimal
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*/
18+
package sub.optimal.util;
19+
20+
import java.io.File;
21+
22+
/**
23+
*
24+
* @author suboptimal
25+
*/
26+
public class FileUtil {
27+
28+
/**
29+
* Check if the passed {@link File} points to an existing file and can be read by the user.
30+
*
31+
* @param file - file to be checked
32+
* @return true - <code>file</code> point to a file and is readable<br>
33+
* false - <code>file</file> is either a directory or is not readable
34+
*/
35+
public static boolean isReadableFile(File file) {
36+
if (!file.exists() || !file.isFile()) {
37+
System.err.println(String.format("%s: does not exist", file.getName()));
38+
return false;
39+
}
40+
if (!file.canRead()) {
41+
System.err.println(String.format("%s: no read permission", file.getName()));
42+
return false;
43+
}
44+
return true;
45+
}
46+
}

0 commit comments

Comments
 (0)