org.codehaus.mojo.license
Class FileUtil

java.lang.Object
  extended by org.codehaus.mojo.license.FileUtil

public class FileUtil
extends Object

Some basic file io utilities

Since:
1.0
Author:
pgier, tchemit

Constructor Summary
FileUtil()
           
 
Method Summary
static void backupFile(File f)
          Backups the given file using the getBackupFile(File) as destination file.
static void copyFile(File source, File target)
          Copy a file to a given locationand logging.
static boolean createDirectoryIfNecessary(File dir)
          Creates the directory (and his parents) if necessary.
static boolean createNewFile(File file)
           
static void deleteFile(File file)
          Delete the given file.
static File getBackupFile(File file)
           
static File getFile(File base, String... paths)
           
static String readAsString(File file, String encoding)
          Permet de lire un fichier et de retourner sont contenu sous forme d'une chaine de carateres
static void renameFile(File file, File destination)
          Rename the given file to a new destination.
static void tryClose(InputStream is)
           
static void tryClose(OutputStream os)
           
static void writeString(File file, String content, String encoding)
          Sauvegarde un contenu dans un fichier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

tryClose

public static void tryClose(InputStream is)

tryClose

public static void tryClose(OutputStream os)

createDirectoryIfNecessary

public static boolean createDirectoryIfNecessary(File dir)
                                          throws IOException
Creates the directory (and his parents) if necessary.

Parameters:
dir - the directory to create if not exisiting
Returns:
true if directory was created, false if was no need to create it
Throws:
IOException - if could not create directory

createNewFile

public static boolean createNewFile(File file)
                             throws IOException
Throws:
IOException

deleteFile

public static void deleteFile(File file)
                       throws IOException
Delete the given file.

Parameters:
file - the file to delete
Throws:
IOException - if could not delete the file

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.

getFile

public static File getFile(File base,
                           String... paths)

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

writeString

public static void writeString(File file,
                               String content,
                               String encoding)
                        throws IOException
Sauvegarde un contenu dans un fichier.

Parameters:
file - le fichier a ecrire
content - le contenu du fichier
encoding - l'encoding d'ecriture
Throws:
IOException - if IO pb


Copyright © 2010-2012 The Kuali Foundation. All Rights Reserved.