com.izforge.izpack.util
Class FileUtil

java.lang.Object
  extended by com.izforge.izpack.util.FileUtil

public class FileUtil
extends Object

Provides general global file utility methods

Author:
marc.eppelmann

Constructor Summary
FileUtil()
           
 
Method Summary
static File convertUrlToFile(URL url)
           
static String convertUrlToFilePath(URL url)
           
static boolean fileContains(String aFileName, String aSearchString)
          Searches case sensitively, and returns true if the given SearchString occurs in the first File with the given Filename.
static boolean fileContains(String aFileName, String aSearchString, boolean caseInSensitiveSearch)
          Tests if the given File contains the given Search String
static File getAbsoluteFile(String filename, String basedir)
          Gets an absolute file from a filename.
static List<String> getFileContent(String fileName)
          Gets the content from a File as StringArray List.
static long getFileDateTime(URL url)
          Gets file date and time.
static String[] getFileNames(String dirPath)
           
static String[] getFileNames(String dirPath, FilenameFilter fileNameFilter)
           
static File getLockFile(String applicationName)
           
static String getRelativeFileName(File file, File basedir)
          Gets a relative file from a filename against a base directory.
 
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

convertUrlToFile

public static File convertUrlToFile(URL url)

convertUrlToFilePath

public static String convertUrlToFilePath(URL url)

getLockFile

public static File getLockFile(String applicationName)

getFileContent

public static List<String> getFileContent(String fileName)
                                   throws IOException
Gets the content from a File as StringArray List.

Parameters:
fileName - A file to read from.
Returns:
List of individual line of the specified file. List may be empty but not null.
Throws:
IOException

fileContains

public static boolean fileContains(String aFileName,
                                   String aSearchString)
Searches case sensitively, and returns true if the given SearchString occurs in the first File with the given Filename.

Parameters:
aFileName - A files name
aSearchString - the string search for
Returns:
true if found in the file otherwise false

fileContains

public static boolean fileContains(String aFileName,
                                   String aSearchString,
                                   boolean caseInSensitiveSearch)
Tests if the given File contains the given Search String

Parameters:
aFileName - A files name
aSearchString - the String to search for
caseInSensitiveSearch - If false the Search is casesensitive
Returns:
true if found in the file otherwise false

getFileDateTime

public static long getFileDateTime(URL url)
Gets file date and time.

Parameters:
url - The URL of the file for which date and time will be returned.
Returns:
Returns long value which is the date and time of the file. If any error occures returns -1 (=no file date and time available).

getFileNames

public static String[] getFileNames(String dirPath)
                             throws Exception
Throws:
Exception

getFileNames

public static String[] getFileNames(String dirPath,
                                    FilenameFilter fileNameFilter)
                             throws Exception
Throws:
Exception

getAbsoluteFile

public static File getAbsoluteFile(String filename,
                                   String basedir)
Gets an absolute file from a filename. In difference to File.isAbsolute() this method bases relative file names on a given base directory.

Parameters:
filename - The filename to build an absolute file from
basedir - The base directory for a relative filename
Returns:
The absolute file according to the described algorithm

getRelativeFileName

public static String getRelativeFileName(File file,
                                         File basedir)
                                  throws IOException
Gets a relative file from a filename against a base directory. Enclosed '.' and '..' characters are resolved for all parameters.

Parameters:
filename - The filename to build a relative file from
basedir - The base directory for a relative filename
Returns:
The relative file name, or null, if one input parameter was null
Throws:
IOException - if the file paths cannot be canonicalized


Copyright © 2015. All rights reserved.