Package org.fest.util
Class Files
java.lang.Object
org.fest.util.Files
Understands utility methods related to files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static FilesException
cannotCreateNewFile
(String path, Exception cause) private static FilesException
cannotCreateNewFile
(String path, String reason) private static FilesException
cannotCreateNewFile
(String path, String reason, Exception cause) static File
Returns the current directory.static void
Deletes the given file or directory.fileNamesIn
(File dir, boolean recurse) Returns the names of the files inside the specified directory.fileNamesIn
(String dirName, boolean recurse) Returns the names of the files inside the specified directory.static void
Flushes and closes the given
.OutputStream
static void
flushAndClose
(Writer writer) Flushes and closes the given
.Writer
static File
Creates a new file using the given path.static File
Creates a new folder using the given path.static File
Creates a new file in the system's temporary folder.static File
Creates a new folder in the system's temporary folder.static File
Returns the system's temporary folder.static String
Returns the path of the system's temporary folder.
-
Constructor Details
-
Files
private Files()
-
-
Method Details
-
fileNamesIn
Returns the names of the files inside the specified directory.- Parameters:
dirName
- the name of the directory to start the search from.recurse
- iftrue
, we will look in subdirectories.- Returns:
- the names of the files inside the specified directory.
- Throws:
IllegalArgumentException
- if the given directory name does not point to an existing directory.
-
fileNamesIn
Returns the names of the files inside the specified directory.- Parameters:
dir
- the name of the directory to start the search from.recurse
- iftrue
, we will look in subdirectories.- Returns:
- the names of the files inside the specified directory.
-
temporaryFolder
Returns the system's temporary folder.- Returns:
- the system's temporary folder.
- Throws:
FilesException
- if this method cannot find or create the system's temporary folder.
-
temporaryFolderPath
Returns the path of the system's temporary folder. This method appends the system's file separator at the end of the path.- Returns:
- the path of the system's temporary folder.
-
newTemporaryFile
Creates a new file in the system's temporary folder. The name of the file will be the result of:concat(String.valueOf(System.currentTimeMillis()), ".txt");
- Returns:
- the created file.
-
newTemporaryFolder
Creates a new folder in the system's temporary folder. The name of the folder will be the result of:System.currentTimeMillis();
- Returns:
- the created file.
-
newFile
Creates a new file using the given path.- Parameters:
path
- the path of the new file.- Returns:
- the new created file.
- Throws:
FilesException
- if the path belongs to an existing non-empty directory.FilesException
- if the path belongs to an existing file.FilesException
- if any I/O error is thrown when creating the new file.
-
newFolder
Creates a new folder using the given path.- Parameters:
path
- the path of the new folder.- Returns:
- the new created folder.
- Throws:
FilesException
- if the path belongs to an existing non-empty directory.FilesException
- if the path belongs to an existing file.FilesException
- if any I/O error is thrown when creating the new folder.
-
cannotCreateNewFile
-
cannotCreateNewFile
-
cannotCreateNewFile
-
flushAndClose
Flushes and closes the given
. Any I/O errors catched by this method are ignored and not rethrown.Writer
- Parameters:
writer
- the writer to flush and close.
-
flushAndClose
Flushes and closes the given
. Any I/O errors catched by this method are ignored and not rethrown.OutputStream
- Parameters:
out
- the output stream to flush and close.
-
currentFolder
Returns the current directory.- Returns:
- the current directory.
- Throws:
FilesException
- if the current directory cannot be obtained.
-
delete
Deletes the given file or directory.- Parameters:
file
- the file or directory to delete.
-