|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.enough.polish.util.FileUtil
public final class FileUtil
Provides some often used methods for handling files.
Copyright Enough Software 2004 - 2011
history
14-Jan-2004 - rob creation
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static void |
addLine(File file,
String line)
Adds the given line to the specified textfile. |
static void |
addLines(File file,
String[] lines)
Adds the given line to the specified textfile. |
static void |
copy(File[] files,
File targetDir)
Copies the given files to the specified target directory. |
static void |
copy(File[] files,
File targetDir,
boolean overwrite)
Copies the given files to the specified target directory. |
static void |
copy(File source,
File target)
Copies a file. |
static void |
copyDirectoryContents(File directory,
File targetDir,
boolean update)
Copies the contents of a directory to the specified target directory. |
static void |
copyDirectoryContents(File directory,
String targetDirName,
boolean update)
Copies the contents of a directory to the specified target directory. |
static boolean |
delete(File file)
Deletes a file or a directory. |
static String[] |
filterDirectory(File dir,
String extension,
boolean recursive)
Retrieves all files from the given directory |
static String[] |
filterDirectory(File dir,
String extension,
FilenameFilter filenameFilter,
boolean recursive)
|
static byte[] |
getBytesFromFile(File file)
Extracts the bytes from a file. |
static Map<String,String> |
readProperties(File file)
Reads properties from the given file. |
static Map<String,String> |
readProperties(InputStream in)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
String encoding)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
String encoding,
boolean translateToAscii,
boolean translateToNative)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
Map<String,String> properties)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
Map<String,String> properties,
String encoding)
Reads properties from the given input stream. |
static void |
readProperties(InputStream in,
char delimiter,
Map<String,String> properties,
String encoding,
boolean translateToAscii,
boolean translateToNative)
Reads properties from the given input stream. |
static Map<String,String> |
readProperties(Reader reader)
Reads properties from the given reader. |
static void |
readProperties(Reader reader,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties)
Reads properties from the given reader. |
static void |
readProperties(Reader reader,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
boolean translateToAscii,
boolean translateToNative)
Reads properties from the given reader. |
static HashMap<String,String> |
readPropertiesFile(File file)
Reads a properties file. |
static HashMap<String,String> |
readPropertiesFile(File file,
char delimiter)
Reads a properties file. |
static void |
readPropertiesFile(File file,
char delimiter,
char comment,
Map<String,String> map,
boolean ignoreInvalidProperties)
Reads a properties file. |
static void |
readPropertiesFile(File file,
char delimiter,
Map<String,String> map)
Reads a properties file. |
static String[] |
readTextFile(File file)
Reads a text file. |
static String[] |
readTextFile(File file,
String encoding)
Reads a text file. |
static String[] |
readTextFile(InputStream in)
Reads the text from the given input stream in the default encoding. |
static String[] |
readTextFile(InputStream in,
String encoding)
Reads the text from the given input stream in the default encoding. |
static String[] |
readTextFile(String fileName)
Reads a text file. |
static void |
writePropertiesFile(File file,
char delimiter,
Map<String,String> properties)
Writes the properties which are defined in the given HashMap into a textfile. |
static void |
writePropertiesFile(File file,
Map<String,String> properties)
Writes the properties which are defined in the given HashMap into a textfile. |
static void |
writeTextFile(File file,
Collection<String> lines)
Writes (and creates) a text file. |
static void |
writeTextFile(File file,
String[] lines)
Writes (and creates) a text file. |
static void |
writeTextFile(File file,
String[] lines,
String encoding)
Writes the given textlines into the specified file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static String[] readTextFile(String fileName)
throws FileNotFoundException,
IOException
fileName - the name of the text file
FileNotFoundException - when the file was not found
IOException - when file could not be read.
public static String[] readTextFile(File file)
throws FileNotFoundException,
IOException
file - the text file
FileNotFoundException - when the file was not found
IOException - when file could not be read.
public static String[] readTextFile(File file,
String encoding)
throws FileNotFoundException,
IOException
file - the text fileencoding - the encoding of the textfile
FileNotFoundException - when the file was not found
IOException - when file could not be read.
public static String[] readTextFile(InputStream in)
throws IOException
in - the input stream
IOException - when stream could not be read.
public static String[] readTextFile(InputStream in,
String encoding)
throws IOException
in - the input streamencoding - the encoding of the textfile
IOException - when stream could not be read.
public static void writeTextFile(File file,
Collection<String> lines)
throws IOException
file - the file to which the text should be writtenlines - the text lines of the file in a collection with String-values
IOException - when there is an input/output error during the saving
public static void writeTextFile(File file,
String[] lines)
throws IOException
file - the file to which the text should be writtenlines - the text lines of the file
IOException - when there is an input/output error during the saving
public static void copy(File[] files,
File targetDir)
throws FileNotFoundException,
IOException
files - The files which should be copied, when an array element is null, it will be ignored.targetDir - The directory to which the given files should be copied to.
FileNotFoundException - when the source file was not found
IOException - when there is an error while copying the file.
NullPointerException - when files or targetDir is null.
public static void copy(File[] files,
File targetDir,
boolean overwrite)
throws FileNotFoundException,
IOException
files - The files which should be copied, when an array element is null, it will be ignored.targetDir - The directory to which the given files should be copied to.overwrite - true when existing target files should be overwritten even when they are newer
FileNotFoundException - when the source file was not found
IOException - when there is an error while copying the file.
NullPointerException - when files or targetDir is null.
public static void copy(File source,
File target)
throws FileNotFoundException,
IOException
source - The file which should be copiedtarget - The file or directory to which the source-file should be copied to.
FileNotFoundException - when the source file was not found
IOException - when there is an error while copying the file.
public static void writePropertiesFile(File file,
Map<String,String> properties)
throws IOException
file - the file which should be created or overwrittenproperties - the properties which should be written.
IOException - when there is an input/output error during the saving
public static void writePropertiesFile(File file,
char delimiter,
Map<String,String> properties)
throws IOException
file - the file which should be created or overwrittendelimiter - the character that separates a property-name from a property-value.properties - the properties which should be written.
IOException - when there is an input/output error during the saving
public static HashMap<String,String> readPropertiesFile(File file)
throws FileNotFoundException,
IOException
file - the file containing the properties
FileNotFoundException - when the file was not found
IOException - when file could not be read.
IllegalArgumentException - when the line does not contain a property
public static HashMap<String,String> readPropertiesFile(File file,
char delimiter)
throws FileNotFoundException,
IOException
file - the file containing the propertiesdelimiter - the character that separates a property-name from a property-value.
FileNotFoundException - when the file was not found
IOException - when file could not be read.
IllegalArgumentException - when the line does not contain a property
public static void readPropertiesFile(File file,
char delimiter,
Map<String,String> map)
throws FileNotFoundException,
IOException
file - the file containing the propertiesdelimiter - the character that separates a property-name from a property-value.map - the hash map to which the properties should be added
FileNotFoundException - when the file was not found
IOException - when file could not be read.
IllegalArgumentException - when the line does not contain a property
public static void readPropertiesFile(File file,
char delimiter,
char comment,
Map<String,String> map,
boolean ignoreInvalidProperties)
throws FileNotFoundException,
IOException
file - the file containing the propertiesdelimiter - the character that separates a property-name from a property-value.comment - the character that introduces a comment, e.g. '#'map - the hash map to which the properties should be addedignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignored
FileNotFoundException - when the file was not found
IOException - when file could not be read.
IllegalArgumentException - when the line does not contain a property
public static void copyDirectoryContents(File directory,
String targetDirName,
boolean update)
throws IOException
directory - the directory containing filestargetDirName - the directory to which the files should be copied toupdate - is true when files should be only copied when the source files
are newer compared to the target files.
IOException - when a file could not be copied
IllegalArgumentException - when the directory is not a directory.
public static void copyDirectoryContents(File directory,
File targetDir,
boolean update)
throws IOException
directory - the directory containing filestargetDir - the directory to which the files should be copied toupdate - set to true when files should be only copied when the source files
are newer compared to the target files.
IOException - when a file could not be copied
IllegalArgumentException - when the directory is not a directory.public static boolean delete(File file)
file - the file or directory which should be deleted.
public static Map<String,String> readProperties(InputStream in)
throws IOException
in - the input stream
IOException - when reading from the input stream fails
public static Map<String,String> readProperties(File file)
throws IOException
file - the file containing properties separated with '='
IOException - when reading from the file fails
FileNotFoundException - when the file does not exist
public static Map<String,String> readProperties(Reader reader)
throws IOException
reader - the input reader
IOException - when reading fails
public static void readProperties(InputStream in,
char delimiter,
Map<String,String> properties)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.properties - a map containing properties
IOException - when reading from the input stream fails
public static void readProperties(InputStream in,
char delimiter,
Map<String,String> properties,
String encoding)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.properties - a map containing propertiesencoding - the encoding of the file
IOException - when reading from the input stream fails
public static void readProperties(InputStream in,
char delimiter,
Map<String,String> properties,
String encoding,
boolean translateToAscii,
boolean translateToNative)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.properties - a map containing propertiesencoding - the encoding of the filetranslateToAscii - true when the FileUtil should translate the code into ASCII only code (using unicode).translateToNative - true when escape sequences like \t or \n should be converted to native characters
IOException - when reading from the input stream fails
public static void readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing properties
IOException - when reading from the input stream fails
public static void readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing propertiesignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignored
IOException - when reading from the input stream fails
IllegalArgumentException - when an invalid property definition is encountered and ignoreInvalidProperties is false
public static void readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
String encoding)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing propertiesignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignoredencoding - the encoding of the text file, when null the default charset is used
IOException - when reading from the input stream fails
IllegalArgumentException - when an invalid property definition is encountered and ignoreInvalidProperties is false
public static void readProperties(Reader reader,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties)
throws IOException
reader - the input readerdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing propertiesignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignored
IOException - when reading from the input stream fails
IllegalArgumentException - when an invalid property definition is encountered and ignoreInvalidProperties is false
public static void readProperties(InputStream in,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
String encoding,
boolean translateToAscii,
boolean translateToNative)
throws IOException
in - the input streamdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing propertiesignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignoredencoding - the encoding of the text file, when null the default charset is usedtranslateToAscii - true when the FileUtil should translate the code into ASCII only code (using unicode).translateToNative - true when escape sequences like \t or \n should be converted to native characters
IOException - when reading from the input stream fails
IllegalArgumentException - when an invalid property definition is encountered and ignoreInvalidProperties is false
public static void readProperties(Reader reader,
char delimiter,
char comment,
Map<String,String> properties,
boolean ignoreInvalidProperties,
boolean translateToAscii,
boolean translateToNative)
throws IOException
reader - the input readerdelimiter - the character that separates a property-name from a property-value.comment - the char denoting commentsproperties - a map containing propertiesignoreInvalidProperties - when this flag is true, invalid property definition (those that do not contain the delimiter char) are ignoredtranslateToAscii - true when the FileUtil should translate the code into ASCII only code (using unicode).translateToNative - true when escape sequences like \t or \n should be converted to native characters
IOException - when reading from the input stream fails
IllegalArgumentException - when an invalid property definition is encountered and ignoreInvalidProperties is false
public static void writeTextFile(File file,
String[] lines,
String encoding)
throws IOException
file - the file to which the text should be writtenlines - the text lines of the fileencoding - the encoding, e.g. "UTF8", null when the default encoding should be used
IOException - when there is an input/output error during the saving
public static void addLine(File file,
String line)
throws IOException
file - the text fileline - the line
IOException - when adding fails.
public static void addLines(File file,
String[] lines)
throws IOException
file - the text filelines - the lines that should be added
IOException - when adding fails.
public static String[] filterDirectory(File dir,
String extension,
boolean recursive)
dir - the directoryextension - the file extension, when the extension is null, all files are includedrecursive - true when subdirectories should also be read.
public static String[] filterDirectory(File dir,
String extension,
FilenameFilter filenameFilter,
boolean recursive)
public static byte[] getBytesFromFile(File file)
throws IOException
file - the file from which the bytes should be extracted from
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||