public class FileUtils
extends java.lang.Object
This static class provides various utility methods for manipulating files.
| Modifier | Constructor and Description |
|---|---|
protected |
FileUtils()
Don't allow instantiation but do allow overrides.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
chdir(java.lang.String directory)
Change the current directory.
|
static boolean |
copyFile(java.lang.String srcFileName,
java.lang.String destFileName)
Copy a file.
|
static boolean |
createPath(java.io.File directory)
Create intermediate directories for a directory path.
|
static boolean |
createPathForFile(java.lang.String fileName)
Create directory for specified file name.
|
static boolean |
deleteFile(java.lang.String fileName)
Delete named file.
|
static java.lang.String |
getCurrentDirectory()
Get the current directory.
|
static java.lang.String |
readTextFile(java.io.File file)
Read text file to a string.
|
static java.lang.String |
readTextFile(java.io.File file,
java.lang.String encoding)
Read text file to a string.
|
static java.lang.String |
readTextFile(java.io.Reader reader)
Read text file to a string.
|
static java.lang.String |
readTextFile(java.lang.String fileName)
Read text file to a string.
|
static java.lang.String |
readTextFile(java.lang.String fileName,
java.lang.String encoding)
Read text file to a string.
|
static void |
writeTextFile(java.io.File file,
boolean append,
java.util.List contents,
java.lang.String encoding)
Write text file from a list of strings.
|
static void |
writeTextFile(java.io.File file,
boolean append,
java.lang.String contents)
Write text file from a string.
|
static void |
writeTextFile(java.io.File file,
boolean append,
java.lang.String[] contents,
java.lang.String encoding)
Write text file from an array of strings.
|
static void |
writeTextFile(java.io.File file,
boolean append,
java.lang.String contents,
java.lang.String encoding)
Write text file from a string.
|
static void |
writeTextFile(java.lang.String fileName,
boolean append,
java.lang.String contents)
Write text file from a string.
|
static void |
writeTextFile(java.lang.String fileName,
boolean append,
java.lang.String contents,
java.lang.String encoding)
Write text file from a string.
|
protected FileUtils()
public static java.lang.String readTextFile(java.io.File file,
java.lang.String encoding)
throws java.io.IOException
file - Text file to read from.encoding - Text file encoding, e.g., "utf-8".java.io.IOException - if file cannot be read.public static java.lang.String readTextFile(java.io.Reader reader)
throws java.io.IOException
reader - Reader to read from.java.io.IOException - if file cannot be read.public static java.lang.String readTextFile(java.io.File file)
throws java.io.IOException
file - Text file to read from.
Assumed to be utf-8 encoded.java.io.IOException - if file cannot be read.public static java.lang.String readTextFile(java.lang.String fileName,
java.lang.String encoding)
throws java.io.IOException
fileName - Text file name to read from.encoding - Text file encoding, e.g., "utf-8".java.io.IOException - if file cannot be read.public static java.lang.String readTextFile(java.lang.String fileName)
throws java.io.IOException
fileName - Text file name to read from.
Assumed to be utf-8 encoded.java.io.IOException - if file cannot be read.public static void writeTextFile(java.io.File file,
boolean append,
java.lang.String contents,
java.lang.String encoding)
throws java.io.IOException
file - Text file to write to.contents - String to write to file.append - True to append contents to existing file.encoding - Text file encoding, e.g., "utf-8".java.io.IOException - in case of I/O exception.public static void writeTextFile(java.io.File file,
boolean append,
java.lang.String[] contents,
java.lang.String encoding)
throws java.io.IOException
file - Text file to write to.contents - Strings to write to file.append - True to append contents to existing file.encoding - Text file encoding, e.g., "utf-8".java.io.IOException - in case of I/O exception.public static void writeTextFile(java.io.File file,
boolean append,
java.util.List contents,
java.lang.String encoding)
throws java.io.IOException
file - Text file to write to.contents - List of strings to write to file.append - True to append contents to existing file.encoding - Text file encoding, e.g., "utf-8".java.io.IOException - in case of I/O exception.public static void writeTextFile(java.io.File file,
boolean append,
java.lang.String contents)
throws java.io.IOException
file - Text file to write to.contents - String to write to file.append - True to append contents to existing file.java.io.IOException - in case of I/O exception.
File is written in utf-8 encoding.
public static void writeTextFile(java.lang.String fileName,
boolean append,
java.lang.String contents,
java.lang.String encoding)
throws java.io.IOException
fileName - Text file name to write to.contents - String to write to file.append - True to append contents to existing file.java.io.IOException - in case of I/O exception.public static void writeTextFile(java.lang.String fileName,
boolean append,
java.lang.String contents)
throws java.io.IOException
fileName - Text file name to write to.contents - String to write to file.append - True to append contents to existing file.java.io.IOException - in case of I/O exception.
File is written in utf-8 encoding.
public static boolean copyFile(java.lang.String srcFileName,
java.lang.String destFileName)
srcFileName - Name of source file to copy.destFileName - Name of destination file to which to copy.public static boolean createPath(java.io.File directory)
directory - The subdirectory for which to create any
missing intermediate directories.public static boolean createPathForFile(java.lang.String fileName)
fileName - File name for which to create
parent directory, if necessary.public static java.lang.String getCurrentDirectory()
public static java.lang.String chdir(java.lang.String directory)
directory - New directory to which to move.
Ignored if null.public static boolean deleteFile(java.lang.String fileName)
fileName - Name of file to delete.