Class FileAccessor

java.lang.Object
ch.nolix.base.environment.filesystem.FileSystemItemAccessor
ch.nolix.base.environment.filesystem.FileAccessor

public final class FileAccessor extends FileSystemItemAccessor
A file accessor can access a given file.
Author:
Silvan Wyss
  • Method Details

    • withFilePath

      public static FileAccessor withFilePath(String filePath)
      Parameters:
      filePath -
      Returns:
      a new FileAccessor for 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

      public void overwriteFile(String content)
      Overwrites the file of this file accessor with the given content.
      Parameters:
      content -
      Throws:
      RuntimeException - if an error occurs.
    • readFile

      public String 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

      public ILinkedList<String> 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.