-
-
Notifications
You must be signed in to change notification settings - Fork 1
System Utilities Documentation
Retrieving system-related properties and file paths is essential for managing applications effectively. Whether you need to access the user's home directory, temporary files, or system properties, the file-worker library provides robust tools for working with system-level information.
Imagine building an application that dynamically configures itself based on the user's environment. This library makes accessing such system details seamless.
- Retrieve user-specific directories such as home, temp, and downloads.
- Fetch system properties like OS name, Java version, and file separators.
- Work with platform-independent system paths.
To include this library in your Java project, add the following dependency:
Replace the variable ${latestVersion} with the current latest version:
Define version in the gradle.properties file:
fileWorkerVersion=${latestVersion}
or in the build.gradle ext area:
fileWorkerVersion = "${latestVersion}"
Then, add the dependency:
implementation("io.github.astrapi69:file-worker:$fileWorkerVersion")
For automatic version updates:
[versions]
file-worker-version=${latestVersion}
[libraries]
file-worker = { module = "io.github.astrapi69:file-worker", version.ref = "file-worker-version" }
Then, add:
implementation libs.file.worker
Maven dependency is now available on Sonatype. Check out the
Sonatype repository
for the latest snapshots and releases.
<properties>
...
<file-worker.version>${latestVersion}</file-worker.version>
...
</properties>
<dependencies>
...
<dependency>
<groupId>io.github.astrapi69</groupId>
<artifactId>file-worker</artifactId>
<version>${file-worker.version}</version>
</dependency>
...
</dependencies>The SystemFileExtensions class provides methods for retrieving system-related file paths.
File homeDir = SystemFileExtensions.getUserHomeDir();
System.out.println("User Home Directory: " + homeDir.getAbsolutePath());File tempDir = SystemFileExtensions.getTempDir();
System.out.println("Temporary Directory: " + tempDir.getAbsolutePath());The SystemFileExtensionsTest class ensures correctness:
@Test
public void testGetUserHomeDir() {
File homeDir = SystemFileExtensions.getUserHomeDir();
assertNotNull(homeDir);
}The SystemPropertiesExtensions class provides methods for retrieving system properties.
String osName = SystemPropertiesExtensions.getOsName();
String javaVersion = SystemPropertiesExtensions.getJavaVersion();
System.out.println("Operating System: " + osName);
System.out.println("Java Version: " + javaVersion);String separator = SystemPropertiesExtensions.getFileSeparator();
System.out.println("File Separator: " + separator);The SystemPropertiesExtensionsTest class ensures property retrieval works:
@Test
public void testGetJavaVersion() {
String javaVersion = SystemPropertiesExtensions.getJavaVersion();
assertNotNull(javaVersion);
}The library allows retrieving and working with platform-independent system paths.
File downloadsDir = SystemFileExtensions.getUserDownloadsDir();
System.out.println("Downloads Directory: " + downloadsDir.getAbsolutePath());File rootDir = SystemFileExtensions.getRootDir();
System.out.println("Root Directory: " + rootDir.getAbsolutePath());@Test
public void testGetRootDir() {
File rootDir = SystemFileExtensions.getRootDir();
assertNotNull(rootDir);
}The library allows modifying system properties dynamically.
Properties properties = new Properties();
properties.setProperty("app.mode", "debug");
SystemPropertiesExtensions.setSystemProperties(properties);
System.out.println("App Mode: " + System.getProperty("app.mode"));@Test
public void testSetSystemProperties() {
Properties props = new Properties();
props.setProperty("test.prop", "value");
SystemPropertiesExtensions.setSystemProperties(props);
assertEquals("value", System.getProperty("test.prop"));
}The file-worker library provides efficient utilities for accessing system-related directories and properties, making it a valuable tool for platform-independent development.
Start using it today to enhance your application's system interactions!
- Create New Files And Directories
- Delete Files Or Directories
- File Comparison Documentation
- File Modification And Merging
- File Reading Documentation
- File Renaming Documentation
- File Search Documentation
- File Sorting Documentation
- File Writing Documentation
- Java File Copy Utilities
- System Utilities Documentation