Class FileUtil


  • public class FileUtil
    extends java.lang.Object
    Useful file utilities.
    Version:
    1.7
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String EXTENSION_SEPARATOR  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyFile​(java.io.File source, java.io.File destination)
      Copies the source file to the destination filename.
      static void deleteFiles​(java.lang.String directoryName)
      Deletes the files in the directory, but does not remove the directory.
      static boolean directoryExists​(java.lang.String directoryName)
      Returns true if the given directory exists.
      static java.lang.String extension​(java.lang.String path)  
      static java.util.List getContents​(java.lang.String textFileName)
      Returns a List of the String's in the text file, one per line.
      static java.lang.String name​(java.lang.String path)  
      static java.lang.String readText​(java.io.File file)
      Gets the contents of a text file as a single String
      static java.lang.String readText​(java.lang.String filename)  
      static void setContents​(java.lang.String textFileName, java.lang.String contents)
      Saves the String with the given filename
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EXTENSION_SEPARATOR

        public static final java.lang.String EXTENSION_SEPARATOR
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileUtil

        public FileUtil()
    • Method Detail

      • name

        public static java.lang.String name​(java.lang.String path)
      • extension

        public static java.lang.String extension​(java.lang.String path)
      • deleteFiles

        public static void deleteFiles​(java.lang.String directoryName)
        Deletes the files in the directory, but does not remove the directory.
      • directoryExists

        public static boolean directoryExists​(java.lang.String directoryName)
        Returns true if the given directory exists.
      • getContents

        public static java.util.List getContents​(java.lang.String textFileName)
                                          throws java.io.FileNotFoundException,
                                                 java.io.IOException
        Returns a List of the String's in the text file, one per line.
        Throws:
        java.io.FileNotFoundException
        java.io.IOException
      • readText

        public static java.lang.String readText​(java.lang.String filename)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readText

        public static java.lang.String readText​(java.io.File file)
                                         throws java.io.IOException
        Gets the contents of a text file as a single String
        Parameters:
        file -
        Returns:
        text file contents
        Throws:
        java.io.IOException
      • setContents

        public static void setContents​(java.lang.String textFileName,
                                       java.lang.String contents)
                                throws java.io.IOException
        Saves the String with the given filename
        Throws:
        java.io.IOException
      • copyFile

        public static void copyFile​(java.io.File source,
                                    java.io.File destination)
                             throws java.io.IOException
        Copies the source file to the destination filename. Posted by Mark Thornton on Usenet.
        Throws:
        java.io.IOException