D.3 The KSLFileUtil Object
The KSLFileUtil Object supports the creation/deletion of files, directories, and working with file extensions. It also facilitates the reading and writing of 1-D and 2-D arrays. Figure D.2 illustrates the functions and properties of the KSLFileUtil object
Figure D.2: KSLFileUtil Class
copyDirectory()andcopyFile()facilitate path and file based copyingcreateFile(),createDirectories(),createPrintWriter(), all create according to their function namesdeleteDirectory()will delete a directory based on aFileor aPathcreateCSVFileName(),createTxtFileName()will make a string that has the appropriate extensionisCSVFile(),isTeXFile(),isTextFile()check for the appropriate extension
As previously noted, there is a logger available for logging file interactions. A useful property is the programLaunchDirectory, which provides the path to the directory in which the program is executing.
The KSLFileUtil object also helps with array IO.
write(array, out: PrintWriter)has versions for working with arrays of primitives:Array<DoubleArray>,Array<IntArray>,DoubleArray,IntArray. The functions that write double values also have an optional argument to control formatting,df: DecimalFormat?. There are equivalent extension functions forArray<DoubleArray>,Array<IntArray>,DoubleArray,IntArrayfor writing to files.scanToArray(path: Path)will read the values file associated with the path into anDoubleArray.toCSVString(array: DoubleArray, df: DecimalFormat?)will format a line representing the array of data as a comma separated value string.
These functions are used in a number of other packages when working with data and files.