com.calitha.io
Class FileUtil

java.lang.Object
  extended by com.calitha.io.FileUtil

public final class FileUtil
extends Object

Author:
Robert van Loenhout

Method Summary
static void append(File file, String text)
          Appends text to a file.
static void append(File file, String text, Charset charset)
          Appends text to a file.
static void copyURLToFile(URL url, File file)
          Copies the content of an URL to a file.
static String fileToString(File file, Charset charset)
          Reads the content of the file and returns it as a string.
static String getExtension(File file)
          Gets the extension part of a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

append

public static void append(File file,
                          String text)
                   throws IOException
Appends text to a file.

The text is appended using the UTF-8 character set.

Parameters:
file - file to append
text - text that will be appended to the file
Throws:
IOException - if an I/O error occurs
IllegalArgumentException - if the file or text argument is null

append

public static void append(File file,
                          String text,
                          Charset charset)
                   throws IOException
Appends text to a file.

Parameters:
file - file to append
text - text that will be appended to the file
charset - the character set used to write the text in the file
Throws:
IOException - if an I/O error occurs
IllegalArgumentException - if the file, text or charset argument is null

getExtension

public static String getExtension(File file)
Gets the extension part of a file.

The extension is the part that occurs after the last dot.

Parameters:
file - file
Returns:
extension, or null if there is no dot
Throws:
IllegalArgumentException - if the file argument is null

copyURLToFile

public static void copyURLToFile(URL url,
                                 File file)
                          throws IOException
Copies the content of an URL to a file.

Parameters:
url - requested URL
file - output file
Throws:
IOException - if an I/O error occurs
IllegalArgumentException - if the url or file argument is null

fileToString

public static String fileToString(File file,
                                  Charset charset)
                           throws IOException
Reads the content of the file and returns it as a string.

Parameters:
file - file that will be used as input
charset - charset/encoding of the file so the bytes can be transformed into a string
Returns:
result string
Throws:
IOException - if an I/O error occurs
IllegalArgumentException - if the file or charset argument is null