Class FileManager

java.lang.Object
rosequartz.files.FileManager

public final class FileManager extends Object
Used to create files completely independent of the platform. There is no working directory, the working directory is always the root, and all paths provided must be relative to the root. Keep in mind that different browsers set different limitations on how much data your game can store, with 2.5MB, 5MB and 10MB being popular values. Projects targeting the web should try to keep their file sizes as low as possible.
  • Constructor Details

  • Method Details

    • get

      public static FileManager get()
      Gets the file manager.
      Returns:
      FileManager-object
      See Also:
      FileManager
    • _process

      public static String _process(String path)
      Makes sure that the given string is formatted in a way that the runtimes can work with.
      Parameters:
      path - path to format
      Returns:
      formatted path
    • fileExists

      public boolean fileExists(String path)
      Gets if a given file path exists.
      Parameters:
      path - the path of the file to check for
      Returns:
      if the file exists
    • filesIn

      public String[] filesIn(String directory)
      Gets an array containing all files in a given directory, excluding directories.
      Parameters:
      directory - directory the files have to be in
      Returns:
      list of all files in a directory
    • directoriesIn

      public String[] directoriesIn(String directory)
      Gets an array containing all directories in a given directory, excluding files.
      Parameters:
      directory - directory the directories have to be a direct child of
      Returns:
      list of all directories in a directory
    • pathsIn

      public String[] pathsIn(String directory)
      Gets an array containing all directories and files in a given directory.
      Parameters:
      directory - directory the directories and files have to be in
      Returns:
      list of all directories and files in a directory
    • writeFileObject

      public void writeFileObject(String path, Serializable data)
      Writes the given object to the given file path. WARNING! Writing objects is not supported by the browser runtime. The browser-runtime will throw a 'PlatformSpecificUnsupportedException'.
      Parameters:
      path - the path of the file to write to
      data - the serializable object to write
      Throws:
      PlatformSpecificUnsupportedException - if called in browser build target
    • writeFileBytes

      public void writeFileBytes(String path, byte[] data)
      Writes the given array of bytes to the given file path.
      Parameters:
      path - the path of the file to write to
      data - the array of bytes to write
    • writeFileString

      public void writeFileString(String path, String data)
      Writes the given string to the given file path.
      Parameters:
      path - the path of the file to write to
      data - the string to write
    • readFileObject

      public Object readFileObject(String path)
      Reads an object from the given file path. WARNING! Reading objects is not supported by the browser runtime. The browser-runtime will throw a 'PlatformSpecificUnsupportedException'.
      Parameters:
      path - the path to read from
      Returns:
      the read object
      Throws:
      PlatformSpecificUnsupportedException - if called in browser build target
    • readFileBytes

      public byte[] readFileBytes(String path)
      Reads an array of bytes from the given file path.
      Parameters:
      path - the path to read from
      Returns:
      the read array of bytes
    • readFileString

      public String readFileString(String path)
      Reads a string from the given file path.
      Parameters:
      path - the path to read from
      Returns:
      the read string
    • deleteFile

      public void deleteFile(String path)
      Deletes a file at the given file path.
      Parameters:
      path - the path to delete
    • copyFile

      public void copyFile(String src, String dest)
      Copies a file to the given file path, replacing if already exists and copying file attributes.
      Parameters:
      src - path of the file to copy
      dest - path of the copy of the file
    • moveFile

      public void moveFile(String src, String dest)
      Moves a file to the given file path.
      Parameters:
      src - path of the file to move
      dest - new path of the moved file