Package com.ibm.wala.util.io
Class FileUtil
- java.lang.Object
-
- com.ibm.wala.util.io.FileUtil
-
public class FileUtil extends Object
Simple utilities for accessing files.
-
-
Constructor Summary
Constructors Constructor Description FileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
copy(String srcFileName, String destFileName)
This may be a resource leak: http://bugs.sun.com/view_bug.do?bug_id=4724038 We may have to reconsider using nio for this, or apply one of the horrible workarounds listed in the bug report above.static FileOutputStream
createFile(String fileName)
Create aFileOutputStream
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 expressionstatic byte[]
readBytes(InputStream s)
read fully the contents of s and return a byte array holding the resultstatic void
recurseFiles(VoidFunction<File> action, Predicate<File> filter, File top)
static void
writeFile(File f, String content)
write string s into file f
-
-
-
Method Detail
-
listFiles
public static Collection<File> listFiles(String dir, String regex, boolean recurse)
List all the files in a directory that match a regular expression- Parameters:
recurse
- recurse to subdirectories?- Throws:
IllegalArgumentException
- if dir is null
-
copy
public static void copy(String srcFileName, String destFileName) throws IOException
This may be a resource leak: http://bugs.sun.com/view_bug.do?bug_id=4724038 We may have to reconsider using nio for this, or apply one of the horrible workarounds listed in the bug report above.- Throws:
IOException
-
deleteContents
public static void deleteContents(String directory) throws IOException
delete all files (recursively) in a directory. This is dangerous. Use with care.- Throws:
IOException
- if there's a problem deleting some file
-
createFile
public static final FileOutputStream createFile(String fileName) throws IOException
Create aFileOutputStream
corresponding to a particular file name. Delete the existing file if one exists.- Throws:
IOException
-
readBytes
public static byte[] readBytes(InputStream s) throws IOException
read fully the contents of s and return a byte array holding the result- Throws:
IOException
-
writeFile
public static void writeFile(File f, String content) throws IOException
write string s into file f- Parameters:
f
-content
-- Throws:
IOException
-
recurseFiles
public static void recurseFiles(VoidFunction<File> action, Predicate<File> filter, File top)
-
-