Class FileSystemAccessor
java.lang.Object
ch.nolix.base.environment.filesystem.FileSystemAccessor
The
FileSystemAccessor can access the file system on the local
machine.- Author:
- Silvan Wyss
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileAccessorcreateFile(String path) Creates a new empty file with the given path.static FileAccessorcreateFile(String path, byte[] content) Creates a new file with the given path.static FileAccessorcreateFile(String path, WriteMode writeMode) Creates a new empty file with the given path.static FileAccessorcreateFile(String path, WriteMode writeMode, byte[] content) Creates a new file with the given path.static FileAccessorcreateFile(String path, WriteMode writeMode, String content) Creates a new file with the given path.static FileAccessorcreateFile(String path, String content) Creates a new file with the given path.static FolderAccessorcreateFolder(String path) Creates a new empty folder with the given path.static voiddeleteFileSystemItem(String path) Deletes the file system item with the given path if it exists.static booleanstatic IContainer<FileAccessor> getFileAccessors(String path) static IContainer<FileAccessor> getFileAccessors(String path, String extension) static ILinkedList<FileAccessor> static IContainer<FileSystemItemAccessor> static FolderAccessorstatic Stringstatic booleanstatic booleanstatic voidOpens the folder of the running jar file in a new file explorer.static voidopenInFileExplorer(String path) Opens the folder with the given path in a new file explorer.static voidoverwriteFile(String path, byte[] content) static voidoverwriteFile(String path, String content) Overwrites the file with the given path.static byte[]readFileToBytes(String filePath) Reads the content of the file with the given filePath to bytes.static ILinkedList<String> readFileToLines(String path) Reads the content of the file with the given path to lines.
-
Method Details
-
getFolderOfRunningJarFile
- Returns:
- a new
FolderAccessorto the folder of the running jar file.
-
getFolderPathOfRunningJarFile
- Returns:
- the path of the folder of the running jar file.
-
openInFileExplorer
Opens the folder with the given path in a new file explorer.- Parameters:
path-
-
openFolderOfRunningJarFileInExplorer
public static void openFolderOfRunningJarFileInExplorer()Opens the folder of the running jar file in a new file explorer. -
createFile
Creates a new empty file with the given path.- Parameters:
path-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is empty.RuntimeException- if there exists already a file system item with the given path.
-
createFile
Creates a new empty file with the given path.- Parameters:
path-writeMode-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is blank.RuntimeException- if the given writeMode flag =WriteMode.THROW_EXCEPTION_WHEN_TARGET_EXISTS_ALREADYand there exists already a file system item with the given path.
-
createFile
Creates a new file with the given path. The file will have the given content.- Parameters:
path-writeMode-content-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is blank.RuntimeException- if the given writeMode =WriteMode.THROW_EXCEPTION_WHEN_TARGET_EXISTS_ALREADYand there exists already a file system item with the given path.RuntimeException- if the given content is null.
-
createFile
Creates a new file with the given path. The file will have the given content.- Parameters:
path-writeMode-content-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is blank.RuntimeException- if the given writeMode =WriteMode.THROW_EXCEPTION_WHEN_TARGET_EXISTS_ALREADYand there exists already a file system item with the given path.RuntimeException- if the given content is null.
-
createFile
Creates a new file with the given path. The file will have the given content.- Parameters:
path-content-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is empty.RuntimeException- if there exists already a file system item with the given path.
-
createFile
Creates a new file with the given path. The file will have the given content.- Parameters:
path-content-- Returns:
- a new
FileAccessorto the created file. - Throws:
RuntimeException- if the given path is null.RuntimeException- if the given path is blank.RuntimeException- if there exists already a file system item with the given path.
-
createFolder
Creates a new empty folder with the given path.- Parameters:
path-- Returns:
- a new
FileAccessorto the created folder. - Throws:
RuntimeException- if there exists already a file system item with the given path.
-
deleteFileSystemItem
Deletes the file system item with the given path if it exists.- Parameters:
path-
-
exists
- Parameters:
path-- Returns:
- true if there exists a file system item with given path, false otherwise.
-
getFileAccessors
- Parameters:
path-- Returns:
- new
FileAccessors for the files in the folder with the given path.
-
getFileAccessors
- Parameters:
path-extension-- Returns:
- new
FileAccessors for the files in the folder with the given path, that have the given extension.
-
getFileAccessorsRecursively
- Parameters:
path-- Returns:
- new
FileAccessors for the files in the folder with the given path recursively.
-
getFileSystemItemAccessors
- Parameters:
path-- Returns:
- new
FileSystemItemAccessors for the file system items in the folder with the given path.
-
isFile
- Parameters:
path-- Returns:
- true if there exists a file with the given path, false otherwise.
-
isFolder
- Parameters:
path-- Returns:
- true if there exists a folder with the given path, false otherwise.
-
overwriteFile
-
overwriteFile
Overwrites the file with the given path. Creates a new file with the given path if it does not exists. The file will get the given content.- Parameters:
path-content-- Throws:
RuntimeException- if there exists already a folder with the given path.
-
readFileToBytes
Reads the content of the file with the given filePath to bytes.- Parameters:
filePath-- Returns:
- the bytes of 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.
-
readFileToLines
Reads the content of the file with the given path to lines.- Parameters:
path-- Returns:
- the lines of the file with the given path.
- Throws:
RuntimeException- if there does not exist a file with the given path.
-