Class FileUtil

java.lang.Object
com.ibm.wala.util.io.FileUtil

public class FileUtil extends Object
Simple utilities for accessing files.
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • 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 a FileOutputStream 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
      Throws:
      IOException
    • recurseFiles

      public static void recurseFiles(Consumer<File> action, Predicate<File> filter, File top)