KSLFileUtil

Provides some basic file utilities. Additional utilities can be found in Google Guava and Apache Commons IO. However, this basic IO provides basic needs without external libraries and is integrated withe KSL functionality.

Properties

Link copied to clipboard
val logger: KLogger

Use for general logging

Link copied to clipboard

Returns the path to the directory that the program was launched from on the OS. This call may throw a SecurityException if the system information is not accessible. Uses System property "user.dir"

Link copied to clipboard

Returns the directory that the program was launched from on the OS as a string. This call may throw a SecurityException if the system information is not accessible. Uses System property "user.dir"

Link copied to clipboard

System.out as a PrintWriter

Functions

Link copied to clipboard
Link copied to clipboard
fun copyDirectory(source: File, destination: File)
fun copyDirectory(source: Path, destination: Path)
Link copied to clipboard

Makes a String that has the form name.csv

Link copied to clipboard

Will throw an IOException if something goes wrong in the creation.

Link copied to clipboard
fun createFile(pathToFile: Path): File
Link copied to clipboard
fun createFileName(theName: String?, theFileExtension: String?): String

Makes a String that has the form name.ext If an extension already exists it is replaced.

Link copied to clipboard

Makes a LogPrintWriter from the given File. IOExceptions are caught and logged. If the file exists it will be written over.

Makes a PrintWriter from the given path, any IOExceptions are caught and logged.

Link copied to clipboard

Makes a PrintWriter from the given File. IOExceptions are caught and logged. If the file exists it is written over.

Makes a PrintWriter from the given path, any IOExceptions are caught and logged. The path must be to a file, not a directory. If the directories that are on the path do not exist, they are created. If the referenced file exists it is written over.

Makes the file in the directory that the program launched within

Link copied to clipboard
fun createSubDirectory(mainDir: Path, dirName: String): Path

Creates a subdirectory within the supplied main directory.

Link copied to clipboard
fun createTemporaryFile(fileName: String, dir: Path = KSL.outDir): File
Link copied to clipboard

Makes a String that has the form name.txt

Link copied to clipboard
fun deleteDirectory(directoryToBeDeleted: File): Boolean

Recursively deletes

fun deleteDirectory(pathToDir: Path): Boolean
Link copied to clipboard

This method will check for the dot ‘.' occurrence in the given filename. If it exists, then it will find the last position of the dot ‘.' and return the characters after that, the characters after the last dot ‘.' known as the file extension. Special Cases:

Link copied to clipboard

This method will check for the dot ‘.' occurrence in the given filename. If it exists, then it will find the last position of the dot ‘.' and return the characters after that, the characters after the last dot ‘.' known as the file extension. Special Cases:

Link copied to clipboard
fun hasCSVExtension(pathToFile: Path): Boolean
Link copied to clipboard
fun isCSVFile(pathToFile: Path?): Boolean
Link copied to clipboard
fun isCSVFileName(fileName: String?): Boolean
Link copied to clipboard
fun isTeXFile(pathToFile: Path?): Boolean
Link copied to clipboard
fun isTexFileName(fileName: String?): Boolean
Link copied to clipboard
fun isTextFile(pathToFile: Path?): Boolean
Link copied to clipboard
fun isTextFileName(fileName: String?): Boolean
Link copied to clipboard
fun openInBrowser(file: File)
fun openInBrowser(fileName: String, html: String, dir: Path = KSL.plotDir): File
Link copied to clipboard
fun removeFileExtension(filename: String?, removeAllExtensions: Boolean): String?
Link copied to clipboard
Link copied to clipboard
fun scanToArray(pathToFile: Path): DoubleArray

Assumes that the file holds doubles with each value on a different line 1.0 4.0 2.0 etc

Link copied to clipboard
fun toCSVString(array: DoubleArray, df: DecimalFormat? = null): String
Link copied to clipboard
fun write(array: Array<IntArray>, out: PrintWriter = SOUT)
fun write(array: IntArray, out: PrintWriter = SOUT)
fun write(array: Array<DoubleArray>, out: PrintWriter = SOUT, df: DecimalFormat? = null)
fun write(array: DoubleArray, out: PrintWriter = SOUT, df: DecimalFormat? = null)

Allows writing directly to a known PrintWriter. Facilitates writing to the file before or after the array is written

fun write(list: List<DoubleArray>, out: PrintWriter = SOUT, df: DecimalFormat? = null)

Allows writing directly to a known PrintWriter. Facilitates writing to the file before or after the list is written

Link copied to clipboard
fun writeToFile(array: Array<IntArray>, pathToFile: Path)
fun writeToFile(array: Array<IntArray>, fileName: String)
fun writeToFile(array: Array<DoubleArray>, pathToFile: Path, df: DecimalFormat? = null)
fun writeToFile(array: Array<DoubleArray>, fileName: String, df: DecimalFormat? = null)

Writes the data in the array to rows in the file, each element in a row is separated by a comma

fun writeToFile(array: IntArray, pathToFile: Path)
fun writeToFile(array: IntArray, fileName: String)
fun writeToFile(array: DoubleArray, pathToFile: Path, df: DecimalFormat? = null): Path
fun writeToFile(array: DoubleArray, fileName: String, df: DecimalFormat? = null): Path

Writes the data in the array to rows in the file, each row with one data point