public final class Files2
extends java.lang.Object
File
s.Modifier and Type | Method and Description |
---|---|
static java.io.File |
getAbsoluteFile(java.lang.Class<?> clazz)
Returns an absolute
File , representing the JAR file or the directory in which clazz can be found. |
static java.util.List<java.io.File> |
getDirectoriesFromDirectory(java.io.File root,
java.util.List<java.io.File> directories)
Adds all
File s that are direct or indirect children to root and file.isDirectory() returns true , to directories , starting from root . |
static java.util.List<java.io.File> |
getFilesFromDirectory(java.io.File root,
java.util.List<java.io.File> files)
Adds all
File s that are direct or indirect children to root and file.isFile() returns true , to files , starting from root . |
static java.io.File |
getUserDataDirectoryFor(java.lang.String projectName,
java.lang.String projectVersion)
Returns a
File denoting the user data directory for the given project name and project version. |
static java.lang.String |
toString(java.io.File file)
Returns a
String containing the text of the file denoted by file . |
public static java.io.File getAbsoluteFile(java.lang.Class<?> clazz)
File
, representing the JAR file or the directory in which clazz
can be found.
If clazz
is null
, a NullPointerException
will be thrown.
If an absolute File
cannot be found, an IllegalStateException
will be thrown.
clazz
- the Class
to find the absolute File
forFile
representing the JAR file or the directory in which clazz
can be foundjava.lang.IllegalStateException
- thrown if, and only if, an absolute File
cannot be foundjava.lang.NullPointerException
- thrown if, and only if, clazz
is null
public static java.io.File getUserDataDirectoryFor(java.lang.String projectName, java.lang.String projectVersion)
File
denoting the user data directory for the given project name and project version.
If either projectName
or projectVersion
are null
, a NullPointerException
will be thrown.
The directory can be located programmatically by the following code, with the assumption that projectName
and projectVersion
cannot be null
.
new File(System.getProperty("user.home") + File.separator + "." + projectName + File.separator + projectVersion)
projectName
- a String
with the project nameprojectVersion
- a String
with the project versionFile
denoting the user data directory for the given project name and project versionjava.lang.NullPointerException
- thrown if, and only if, either projectName
or projectVersion
are null
public static java.util.List<java.io.File> getDirectoriesFromDirectory(java.io.File root, java.util.List<java.io.File> directories)
File
s that are direct or indirect children to root
and file.isDirectory()
returns true
, to directories
, starting from root
.
Returns directories
.
If either root
or directories
are null
, a NullPointerException
will be thrown.
If root.isDirectory()
returns false
, directories
will be returned, in its initial state.
root
- the root directorydirectories
- the List
to add to and returndirectories
java.lang.NullPointerException
- thrown if, and only if, either root
or directories
are null
public static java.util.List<java.io.File> getFilesFromDirectory(java.io.File root, java.util.List<java.io.File> files)
File
s that are direct or indirect children to root
and file.isFile()
returns true
, to files
, starting from root
.
Returns files
.
If either root
or files
are null
, a NullPointerException
will be thrown.
If root.isDirectory()
returns false
, files
will be returned, in its initial state.
root
- the root directoryfiles
- the List
to add to and returnfiles
java.lang.NullPointerException
- thrown if, and only if, either root
or files
are null
public static java.lang.String toString(java.io.File file)
String
containing the text of the file denoted by file
.
If file
is null
, a NullPointerException
will be thrown.
If the file cannot be read, an UncheckedIOException
will be thrown.
file
- the File
denoting the file to read text fromString
containing the text of the file denoted by file
java.lang.NullPointerException
- thrown if, and only if, file
is null
java.io.UncheckedIOException
- thrown if, and only if, the file cannot be read