jcreek.cke.util
Class FileUtilities

java.lang.Object
  extended byjcreek.cke.util.FileUtilities

public class FileUtilities
extends java.lang.Object

Contains some basic file utilities that could be very handy in certain situations.

Author:
Stein L. Tomassen, NTNU 2002

Constructor Summary
FileUtilities()
           
 
Method Summary
static boolean delFile(java.lang.String filename)
          Deletes the specified file or directory if exists.
static boolean exists(java.lang.String pathname)
          Checks that the specified pathname is an existing file or directory.
static java.lang.String getDirContent(java.lang.String pathname)
          Gets the filenames and directories of the specified directory
static java.lang.String getFileFormatedDate()
          A method that returns a date formatted as "yyyyMMddHHmmssSSS".
static java.lang.String getLogFormatedDate()
          A method that returns a date formatted as "yyyy-MM-dd HH:mm:ss:SSS".
static boolean isDirectory(java.lang.String pathname)
          Checks if the specified pathname is a directory
static boolean isFile(java.lang.String filename)
          Checks if the specified filename is a file
static java.lang.String readFromFile(java.lang.String filename)
          Gets the content of the specified file in string format
static java.lang.String setPathSlash(java.lang.String path)
          A method that guaranties that a directory path ends with a slash.
static java.lang.String setXMLOutputFormat(java.lang.String path, java.lang.String name)
          A method that returns a filename formatted as "[path]/yyyyMMddHHmmssSSS-[Name].xml".
static boolean writeToFile(java.lang.String filename, java.lang.String content)
          Writes the content to the specified file.
static boolean writeToFile(java.lang.String filename, java.lang.String content, boolean append)
          Writes the content to the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtilities

public FileUtilities()
Method Detail

getLogFormatedDate

public static java.lang.String getLogFormatedDate()
A method that returns a date formatted as "yyyy-MM-dd HH:mm:ss:SSS".

Returns:
the formatted date as a string

getFileFormatedDate

public static java.lang.String getFileFormatedDate()
A method that returns a date formatted as "yyyyMMddHHmmssSSS".

Returns:
the formatted date as a string

setPathSlash

public static java.lang.String setPathSlash(java.lang.String path)
A method that guaranties that a directory path ends with a slash.

Parameters:
path - the path to check and alter
Returns:
the path with ending slash

setXMLOutputFormat

public static java.lang.String setXMLOutputFormat(java.lang.String path,
                                                  java.lang.String name)
A method that returns a filename formatted as "[path]/yyyyMMddHHmmssSSS-[Name].xml".

Parameters:
path - of the file
name - of the file
Returns:
the formatted file as a string

exists

public static boolean exists(java.lang.String pathname)
Checks that the specified pathname is an existing file or directory.

Parameters:
pathname - of the specified file or directory
Returns:
true if the specified file or directory exist, otherwise false.

isDirectory

public static boolean isDirectory(java.lang.String pathname)
Checks if the specified pathname is a directory

Parameters:
pathname - the pathname to check
Returns:
true if the pathname is a directory, otherwise false

isFile

public static boolean isFile(java.lang.String filename)
Checks if the specified filename is a file

Parameters:
filename - the filename to check
Returns:
true if the filename is a file, otherwise false

delFile

public static boolean delFile(java.lang.String filename)
Deletes the specified file or directory if exists. Note that the directory must be empty to be removed.

Returns:
true if removal was successful, otherwise false

readFromFile

public static java.lang.String readFromFile(java.lang.String filename)
Gets the content of the specified file in string format

Parameters:
filename - name of the specified file
Returns:
the content of the specified file as string, does otherwise return null in a case of an error

getDirContent

public static java.lang.String getDirContent(java.lang.String pathname)
Gets the filenames and directories of the specified directory

Parameters:
pathname - of the specified directory
Returns:
a string with the directory content delimited with a new line character, otherwise returns nothing if an error occurred

writeToFile

public static boolean writeToFile(java.lang.String filename,
                                  java.lang.String content,
                                  boolean append)
Writes the content to the specified file.

Parameters:
filename - name of the specified file
content - that should be written to the specified file
append - true if append to file if it exist or false if overwrite the file if it exist
Returns:
true if successful, otherwise false

writeToFile

public static boolean writeToFile(java.lang.String filename,
                                  java.lang.String content)
Writes the content to the specified file. Note that this method overwrites the file it it exist.

Parameters:
filename - name of the specified file
content - that should be written to the specified file
Returns:
true if successful, otherwise false


Created at IDI, NTNU by the Artificial Intelligence and Learning group