public class FileUtil extends Object
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(String srcFileName,
String destFileName)
This may be a resource leak: http://bugs.sun.com/view_bug.do?bug_id=4724038
|
static FileOutputStream |
createFile(String fileName)
Create a
FileOutputStream corresponding to a particular file name. |
static void |
deleteContents(String directory)
delete all files (recursively) in a directory.
|
static Collection<File> |
listFiles(String dir,
String regex,
boolean recurse)
List all the files in a directory that match a regular expression
|
static byte[] |
readBytes(InputStream s)
read fully the contents of s and return a byte array holding the result
|
static void |
recurseFiles(Consumer<File> action,
Predicate<File> filter,
File top) |
static void |
writeFile(File f,
String content)
write string s into file f
|
public static Collection<File> listFiles(String dir, String regex, boolean recurse)
recurse - recurse to subdirectories?IllegalArgumentException - if dir is nullpublic static void copy(String srcFileName, String destFileName) throws IOException
We may have to reconsider using nio for this, or apply one of the horrible workarounds listed in the bug report above.
IOExceptionpublic static void deleteContents(String directory) throws IOException
IOException - if there's a problem deleting some filepublic static final FileOutputStream createFile(String fileName) throws IOException
FileOutputStream corresponding to a particular file name. Delete the existing
file if one exists.IOExceptionpublic static byte[] readBytes(InputStream s) throws IOException
IOExceptionpublic static void writeFile(File f, String content) throws IOException
IOException