Files
Overview
Module
- package:
org.eclipse.dirigible.sdk.io - source: io/Files.java
Filesystem operations against the operating-system view — read/write content, query metadata, change permissions, copy or move entries. Paths are absolute OS paths (not registry paths); to read or write artefacts under /registry/public/... or a project workspace use org.eclipse.dirigible.sdk.platform.Registry or org.eclipse.dirigible.sdk.platform.Workspace instead.
Every method propagates IOException from the platform — callers should funnel them up to a controller or background-job boundary that knows what to do with them.
Key Features:
- Property checks:
exists,isFile,isDirectory,isReadable,isWritable,isExecutable,isHidden,isSameFile. - Content I/O: Read and write text or bytes against absolute OS paths.
- Metadata: Last-modified time, owner, permissions, size; getters and setters where supported.
- Lifecycle: Create files and directories, copy or move them, delete files.
Example Usage:
import org.eclipse.dirigible.sdk.io.Files;
String contents = Files.readText("/var/data/import.csv");
Files.writeText("/var/data/out.json", json);
String target = "/var/data/archive";
if (!Files.exists(target)) {
Files.createDirectory(target);
}Methods
exists()
Checks if a file or directory exists at the given path.
javapublic static boolean exists(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif the path exists,falseotherwise.
isExecutable()
Checks if the file or directory at the given path is executable.
javapublic static boolean isExecutable(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif executable,falseotherwise.
isReadable()
Checks if the file or directory at the given path is readable.
javapublic static boolean isReadable(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif readable,falseotherwise.
isWritable()
Checks if the file or directory at the given path is writable.
javapublic static boolean isWritable(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif writable,falseotherwise.
isHidden()
Checks if the file or directory at the given path is hidden.
javapublic static boolean isHidden(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif hidden,falseotherwise.
isDirectory()
Checks if the path refers to a directory.
javapublic static boolean isDirectory(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif it's a directory,falseotherwise.
isFile()
Checks if the path refers to a regular file.
javapublic static boolean isFile(String path) throws IOException;
Parameter Type Description pathStringThe path to check. Returns
- Type:
boolean- Description:
trueif it's a file,falseotherwise.
isSameFile()
Checks if two paths refer to the same underlying file system object.
javapublic static boolean isSameFile(String path1, String path2) throws IOException;
Parameter Type Description path1StringThe first path. path2StringThe second path. Returns
- Type:
boolean- Description:
trueif both paths reference the same file/directory,falseotherwise.
getCanonicalPath()
Returns the canonical (absolute and normalized) path for the given path.
javapublic static String getCanonicalPath(String path) throws IOException;
Parameter Type Description pathStringThe path to normalize. Returns
- Type:
String- Description: The canonical path string.
getName()
Gets the simple name of the file or directory at the given path (the last element).
javapublic static String getName(String path) throws IOException;
Parameter Type Description pathStringThe path. Returns
- Type:
String- Description: The simple name.
getParentPath()
Gets the path of the parent directory.
javapublic static String getParentPath(String path) throws IOException;
Parameter Type Description pathStringThe path. Returns
- Type:
String- Description: The parent path string, or
null/empty if none exists.
readBytes()
Reads all bytes from a file.
javapublic static byte[] readBytes(String path) throws IOException;
Parameter Type Description pathStringThe path to the file. Returns
- Type:
byte[]- Description: The contents of the file as a byte array.
readText()
Reads all text content from a file using the platform's default character encoding.
javapublic static String readText(String path) throws IOException;
Parameter Type Description pathStringThe path to the file. Returns
- Type:
String- Description: The content of the file as a string.
writeText()
Writes a string of text to a file using the platform's default character encoding. Overwrites existing content.
javapublic static void writeText(String path, String text) throws IOException;
Parameter Type Description pathStringThe path to the file. textStringThe string content to write. Returns
- Type:
void
writeBytes()
Writes the supplied string-encoded byte input to a file. Overwrites existing content. For raw byte[] payloads, prefer writeBytesNative.
javapublic static void writeBytes(String path, String input) throws IOException;
Parameter Type Description pathStringThe path to the file. inputStringThe string-encoded byte data to write. Returns
- Type:
void
writeBytesNative()
Writes a native Java byte array to a file. Overwrites existing content.
javapublic static void writeBytesNative(String path, byte[] input) throws IOException;
Parameter Type Description pathStringThe path to the file. inputbyte[]The byte array to write. Returns
- Type:
void
getLastModified()
Gets the last modified time of the file or directory, in milliseconds since the epoch.
javapublic static long getLastModified(String path) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. Returns
- Type:
long- Description: The last-modified time in milliseconds since the epoch.
setLastModified()
Sets the last modified time of the file or directory.
javapublic static void setLastModified(String path, long time) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. timelongThe new last-modified time in milliseconds since the epoch. Returns
- Type:
void
getOwner()
Gets the owner of the file or directory.
javapublic static String getOwner(String path) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. Returns
- Type:
String- Description: The owner name as a string.
setOwner()
Sets the owner of the file or directory.
javapublic static void setOwner(String path, String owner) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. ownerStringThe new owner name. Returns
- Type:
void
getPermissions()
Gets the permissions string for the file or directory (implementation dependent).
javapublic static String getPermissions(String path) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. Returns
- Type:
String- Description: The permissions string.
setPermissions()
Sets the permissions for the file or directory (implementation dependent).
javapublic static void setPermissions(String path, String permissions) throws IOException;
Parameter Type Description pathStringThe path to the file or directory. permissionsStringThe permissions string. Returns
- Type:
void
size()
Gets the size of the file in bytes.
javapublic static long size(String path) throws IOException;
Parameter Type Description pathStringThe path to the file. Returns
- Type:
long- Description: The size in bytes.
createFile()
Creates a new, empty file at the specified path.
javapublic static void createFile(String path) throws IOException;
Parameter Type Description pathStringThe path where the file should be created. Returns
- Type:
void
createDirectory()
Creates a new directory at the specified path.
javapublic static void createDirectory(String path) throws IOException;
Parameter Type Description pathStringThe path where the directory should be created. Returns
- Type:
void
copy()
Copies a file or directory from a source path to a target path.
javapublic static void copy(String source, String target) throws IOException;
Parameter Type Description sourceStringThe source path. targetStringThe target path. Returns
- Type:
void
move()
Moves or renames a file or directory.
javapublic static void move(String source, String target) throws IOException;
Parameter Type Description sourceStringThe source path. targetStringThe target path. Returns
- Type:
void
deleteFile()
Deletes the file at the specified path.
javapublic static void deleteFile(String path) throws IOException;
Parameter Type Description pathStringThe path to the file to delete. Returns
- Type:
void