public class FileServices
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
FileServices() |
Modifier and Type | Method and Description |
---|---|
static void |
appendToFile(java.lang.String filePath,
java.lang.String text)
Creates a new file if necessary with the specified file path and appends the specified text to the file.
|
static void |
appendToFile(java.lang.String filePath,
java.lang.String text,
java.lang.String encoding)
Creates a new file if necessary with the specified file path and appends the specified text decoded using the specified encoding to the file.
|
static byte[] |
base64Decode(java.lang.String encoded)
Returns decoded text from a base64 string.
|
static java.lang.String |
base64Encode(byte[] bytes)
Returns the text as a Base64 encoded string
|
static java.lang.String |
base64EncodeFile(java.lang.String filename)
Returns the text as a Base64 encoded string
|
static boolean |
copyFile(java.lang.String fromPath,
java.lang.String toPath)
Copies the contents of the file represented by fromPath to toPath.
|
static boolean |
createNewDirectory(java.lang.String filePath)
Creates a new directory with this path name including any necessary but nonexistent parent directories.
|
static boolean |
createNewFile(java.lang.String filePath)
Creates a new file with this path name so long as a file or directory doesn't already exist with the same name.
|
static boolean |
deleteFile(java.lang.String filePath)
Deletes the file or directory with this path name.
|
static boolean |
existsFile(java.lang.String filePath)
Returns true if a file or directory with this path name exists.
|
static java.lang.String |
getAbsoluteFilePath(java.lang.String filePath)
Returns an absolute file path for the specified relative or absolute file path.
|
static java.lang.String |
getParentPath(java.lang.String filePath)
Returns the path name of this file's parent directory or null if no parent exists.
|
static java.lang.String |
getSeparator()
Returns the system dependent file separator character.
|
static java.lang.String |
getWebAppRootFilePath()
Returns the file path for the root directory served by Http requests for the web application.
|
static boolean |
isDirectory(java.lang.String filePath)
Returns true if file path represents a directory.
|
static boolean |
isFile(java.lang.String filePath)
Returns true if file path represents a file.
|
static java.lang.String[] |
listFilesInDirectory(java.lang.String filePath)
Returns an array of file paths for all files and directories within the directory represented by file path.
|
static boolean |
moveFile(java.lang.String fromPath,
java.lang.String toPath)
Moves the file specified by fromPath to the path specified by toPath.
|
static java.lang.String |
readFile(java.lang.String filePath)
Returns a String value representing the contents of the file specified by file path.
|
static java.lang.String |
readFile(java.lang.String filePath,
java.lang.String encoding)
Returns a String value representing the contents of the file specified by file path decoded using the specified encoding.
|
static void |
writeFile(java.lang.String filePath,
java.lang.String text)
Creates a new file if necessary with the specified file path and saves the file with the specified text.
|
static void |
writeFile(java.lang.String filePath,
java.lang.String text,
java.lang.String encoding)
Creates a new file if necessary with the specified file path and saves the file with the specified text decoded using the specified encoding.
|
public static boolean createNewDirectory(java.lang.String filePath) throws java.io.IOException
filePath
- for the new directoryjava.io.IOException
- if an error occurspublic static boolean createNewFile(java.lang.String filePath) throws java.io.IOException
filePath
- file path for the new filejava.io.IOException
- if an error occurspublic static boolean deleteFile(java.lang.String filePath) throws java.io.IOException
filePath
- to be deletedjava.io.IOException
- if an error occurspublic static boolean existsFile(java.lang.String filePath)
filePath
- public static java.lang.String getParentPath(java.lang.String filePath)
filePath
- public static boolean isDirectory(java.lang.String filePath)
filePath
- public static boolean isFile(java.lang.String filePath)
filePath
- public static java.lang.String[] listFilesInDirectory(java.lang.String filePath)
filePath
- public static java.lang.String readFile(java.lang.String filePath) throws java.io.IOException
filePath
- java.io.IOException
- if an error occurspublic static java.lang.String readFile(java.lang.String filePath, java.lang.String encoding) throws java.io.IOException
filePath
- encoding
- character set namejava.io.IOException
- if an error occurspublic static boolean moveFile(java.lang.String fromPath, java.lang.String toPath) throws java.io.IOException
fromPath
- the file to be renamedtoPath
- the new namejava.io.IOException
- if an error occurspublic static void appendToFile(java.lang.String filePath, java.lang.String text) throws java.io.IOException
filePath
- text
- text to be append to the filejava.io.IOException
- if an error occurspublic static void appendToFile(java.lang.String filePath, java.lang.String text, java.lang.String encoding) throws java.io.IOException
filePath
- text
- text to be append to the fileencoding
- character set namejava.io.IOException
- if an error occurspublic static void writeFile(java.lang.String filePath, java.lang.String text) throws java.io.IOException
filePath
- text
- text to be savedjava.io.IOException
- if an error occurspublic static void writeFile(java.lang.String filePath, java.lang.String text, java.lang.String encoding) throws java.io.IOException
filePath
- text
- text to be savedencoding
- character set namejava.io.IOException
- if an error occurspublic static boolean copyFile(java.lang.String fromPath, java.lang.String toPath) throws java.io.IOException
fromPath
- the file to be copiedtoPath
- the target filejava.io.IOException
- if an error occurspublic static java.lang.String getSeparator()
public static java.lang.String getWebAppRootFilePath()
public static java.lang.String getAbsoluteFilePath(java.lang.String filePath) throws java.io.IOException
filePath
- java.io.IOException
public static final java.lang.String base64EncodeFile(java.lang.String filename) throws java.io.IOException
filename
- to encodejava.io.IOException
public static final java.lang.String base64Encode(byte[] bytes)
bytes
- to encodepublic static final byte[] base64Decode(java.lang.String encoded)
encoded
- text to decode