Class FileUtil


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

      • FileUtil

        public FileUtil()
    • 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
      • 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