FileUtil
FileUtil class provides utility methods for working with files in your application. It includes methods for reading, creating, and managing files.
Methods
readFile(filePath: String): File
readFile(filePath: String): FileReads the content of a file located at the specified filePath and returns a File object representing the file.
Parameters:
filePath(String): The path to the file to be read.
Returns:
File: AFileobject representing the read file.
// Read a file
var filePath = "path/to/your/file.txt";
var file = FileUtil.readFile(filePath);readInputStream(inputStream: InputStream, relativeIterationPath: String): File
readInputStream(inputStream: InputStream, relativeIterationPath: String): FileReads the content of an input stream and creates a File object. The relativeIterationPath is used to determine the file path for the created File object.
Parameters:
inputStream(InputStream): The input stream to read.relativeIterationPath(String): The relative path for the createdFileobject.
Returns:
File: AFileobject representing the read content.
createFile(filePath: String, content: String): File
createFile(filePath: String, content: String): FileCreates a new file at the specified filePath with the provided content.
Parameters:
filePath(String): The path for the new file.content(String): The content to be written to the file.
Returns:
File: AFileobject representing the newly created file.
createTempFile(fileName: String, content: String): File
createTempFile(fileName: String, content: String): FileCreates a temporary file with the specified fileName and writes the provided content to it.
Parameters:
fileName(String): The name for the temporary file.content(String): The content to be written to the file.
Returns:
File: AFileobject representing the created temporary file.
readFileContent(fileName: String): String
readFileContent(fileName: String): StringReads the content of a file with the specified fileName and returns it as a string.
Parameters:
fileName(String): The name of the file to read.
Returns:
String: The content of the file as a string.
Examples
Logging Data to a File:
Generating Reports:
Reading Customer Data:
Data Backup and Recovery:
Was this helpful?