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, @Language("RegExp") 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
      Copies a file from the specified source path to the destination path, replacing the destination if it already exists.
      Parameters:
      srcFileName - the path of the source file
      destFileName - the path of the destination file
      Throws:
      IOException - if an I/O error occurs during the copy operation
    • 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 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)