Class FileAccessor
java.lang.Object
ch.nolix.base.environment.filesystem.FileSystemItemAccessor
ch.nolix.base.environment.filesystem.FileAccessor
A file accessor can access a given file.
- Author:
- Silvan Wyss
-
Method Summary
Modifier and TypeMethodDescriptionvoidClears the file of this file accessor.voidoverwriteFile(byte[] bytes) Overwrites the file of this file accessor with the given bytes.voidoverwriteFile(String content) Overwrites the file of this file accessor with the given content.readFile()Reads the content of the file of this file accessor.byte[]Reads the content of the file of this file accessor to bytes.Reads the content of the file of this file accessor to lines.static FileAccessorwithFilePath(String filePath) Methods inherited from class FileSystemItemAccessor
getExtension, getName, getParentFolderAccessor, getPath, getSizeInBytes, hasExtension, isFile, isFolder, openParentFolder, withPath
-
Method Details
-
withFilePath
- Parameters:
filePath-- Returns:
- a new
FileAccessorfor the file with the given filePath. - Throws:
RuntimeException- if there does not exist a file with the given filePath in the file system on the local machine.
-
clearFile
public void clearFile()Clears the file of this file accessor. Deletes the content of the file of this file accessor, but not the file itself. -
overwriteFile
public void overwriteFile(byte[] bytes) Overwrites the file of this file accessor with the given bytes.- Parameters:
bytes-- Throws:
RuntimeException- if an error occurs.
-
overwriteFile
Overwrites the file of this file accessor with the given content.- Parameters:
content-- Throws:
RuntimeException- if an error occurs.
-
readFile
Reads the content of the file of this file accessor.- Returns:
- the content of the file of this file accessor.
- Throws:
RuntimeException- if an error occurs.
-
readFileToBytes
public byte[] readFileToBytes()Reads the content of the file of this file accessor to bytes.- Returns:
- the bytes of the file of this file accessor.
- Throws:
RuntimeException- if an error occurs.
-
readFileToLines
Reads the content of the file of this file accessor to lines.- Returns:
- the lines of the file of this file accessor.
- Throws:
RuntimeException- if an error occurs.
-