Package org.apache.juneau.commons.utils
Class FileUtils
java.lang.Object
org.apache.juneau.commons.utils.FileUtils
File utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCreates a file if it doesn't already exist usingFile.createNewFile().static FilecreateTempFile(String name) Create a temporary file with the specified name.static FilecreateTempFile(String name, String contents) Create a temporary file with the specified name and specified contents.static booleandeleteFile(File f) Recursively deletes a file or directory.static booleanfileExists(File dir, String fileName) Returnstrue if the specified file exists in the specified directory.static StringgetBaseName(String name) Strips the extension from a file name.static StringgetFileExtension(String name) Returns the extension from a file name.static StringgetFileName(String path) Given an arbitrary path, returns the file name portion of that path.static booleanhasExtension(String name, String ext) Returnstrue if the specified file name contains the specified extension.static FileSame asFile.mkdirs()except throws a RuntimeExeption if directory could not be created.static FileSame asmkdirs(String, boolean)but uses String path.static voidUpdates the modified timestamp on the specified file.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
create
Creates a file if it doesn't already exist usingFile.createNewFile().Throws a
RuntimeExceptionif the file could not be created.- Parameters:
f- The file to create.
-
createTempFile
Create a temporary file with the specified name.The name is broken into file name and suffix, and the parts are passed to
File.createTempFile(String, String).File.deleteOnExit()is called on the resulting file before being returned by this method.- Parameters:
name- The file name- Returns:
- A newly-created temporary file.
- Throws:
IOException- Thrown by underlying stream.
-
createTempFile
Create a temporary file with the specified name and specified contents.The name is broken into file name and suffix, and the parts are passed to
File.createTempFile(String, String).File.deleteOnExit()is called on the resulting file before being returned by this method.- Parameters:
name- The file namecontents- The file contents.- Returns:
- A newly-created temporary file.
- Throws:
IOException- Thrown by underlying stream.
-
deleteFile
Recursively deletes a file or directory.- Parameters:
f- The file or directory to delete.- Returns:
true if file or directory was successfully deleted.
-
fileExists
Returnstrue if the specified file exists in the specified directory.- Parameters:
dir- The directory.fileName- The file name.- Returns:
true if the specified file exists in the specified directory.
-
getBaseName
Strips the extension from a file name.- Parameters:
name- The file name.- Returns:
- The file name without the extension, or
null if name wasnull .
-
getFileExtension
Returns the extension from a file name.- Parameters:
name- The file name.- Returns:
- The the extension, or
null if name wasnull .
-
getFileName
Given an arbitrary path, returns the file name portion of that path.- Parameters:
path- The path to check.- Returns:
- The file name.
-
hasExtension
Returnstrue if the specified file name contains the specified extension.- Parameters:
name- The file name.ext- The extension.- Returns:
true if the specified file name contains the specified extension.
-
mkdirs
Same asFile.mkdirs()except throws a RuntimeExeption if directory could not be created.- Parameters:
f- The directory to create. Must not benull .clean- Iftrue , deletes the contents of the directory if it already exists.- Returns:
- The same file.
- Throws:
RuntimeException- if directory could not be created.
-
mkdirs
Same asmkdirs(String, boolean)but uses String path.- Parameters:
path- The path of the directory to create. Must not benull clean- Iftrue , deletes the contents of the directory if it already exists.- Returns:
- The directory.
-
modifyTimestamp
Updates the modified timestamp on the specified file.Method ensures that the timestamp changes even if it's been modified within the past millisecond.
- Parameters:
f- The file to modify the modified timestamp on.
-