Package org.apache.juneau.internal
Class FileUtils
java.lang.Object
org.apache.juneau.internal.FileUtils
File utilities.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Creates a file if it doesn't already exist usingFile.createNewFile()
.static File
createTempFile
(String name) Create a temporary file with the specified name.static File
createTempFile
(String name, String contents) Create a temporary file with the specified name and specified contents.static boolean
Recursively deletes a file or directory.static boolean
Returnstrue if the specified file exists in the specified directory.static String
getBaseName
(String name) Strips the extension from a file name.static String
getExtension
(String name) Returns the extension from a file name.static String
getFileName
(String path) Given an arbitrary path, returns the file name portion of that path.static boolean
hasExtension
(String name, String ext) Returnstrue if the specified file name contains the specified extension.static File
Same asFile.mkdirs()
except throws a RuntimeExeption if directory could not be created.static File
Same asmkdirs(String, boolean)
but uses String path.static void
Updates the modified timestamp on the specified file.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
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.
-
delete
Recursively deletes a file or directory.- Parameters:
f
- The file or directory to delete.- Returns:
true if file or directory was successfully deleted.
-
create
Creates a file if it doesn't already exist usingFile.createNewFile()
.Throws a
RuntimeException
if the file could not be created.- Parameters:
f
- The file to create.
-
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.
-
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.
-
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 .
-
getExtension
Returns the extension from a file name.- Parameters:
name
- The file name.- Returns:
- The the extension, or
null if name wasnull .
-
exists
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.
-
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.
-
getFileName
Given an arbitrary path, returns the file name portion of that path.- Parameters:
path
- The path to check.- Returns:
- The file name.
-