Class FileUtil

java.lang.Object
org.codehaus.mojo.license.utils.FileUtil

public class FileUtil extends Object
Some basic file io utilities
Since:
1.0
Author:
pgier, tchemit dev@tchemit.fr
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • renameFile

      public static void renameFile(File file, File destination) throws IOException
      Rename the given file to a new destination.
      Parameters:
      file - the file to rename
      destination - the destination file
      Throws:
      IOException - if could not rename the file
    • copyFile

      public static void copyFile(File source, File target) throws IOException
      Copy a file to a given locationand logging.
      Parameters:
      source - represents the file to copy.
      target - file name of destination file.
      Throws:
      IOException - if could not copy file.
    • getBackupFile

      public static File getBackupFile(File file)
      Parameters:
      file - the source file
      Returns:
      the backup file
    • backupFile

      public static void backupFile(File f) throws IOException
      Backups the given file using the getBackupFile(File) as destination file.
      Parameters:
      f - the file to backup
      Throws:
      IOException - if any pb while copying the file
    • readAsString

      public static String readAsString(File file, String encoding) throws IOException
      Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres.
      Parameters:
      file - le fichier a lire
      encoding - encoding to read file
      Returns:
      the content of the file
      Throws:
      IOException - if IO pb
    • printString

      public static void printString(File file, String content, String encoding) throws IOException
      Print content to file. This method ensures that a platform specific line ending is used.
      Parameters:
      file - the file to write to
      content - the content to write
      encoding - the encoding to write in
      Throws:
      IOException - if IO pb
    • orderFiles

      public static List<File> orderFiles(Collection<File> files)
    • sha1

      public static String sha1(Path in) throws IOException
      Throws:
      IOException
    • toExtension

      public static String toExtension(String mimeType, boolean throwDefault)