https://github.com/robtimus/application-path
Provides utility classes for querying application specific paths
https://github.com/robtimus/application-path
application java
Last synced: 3 months ago
JSON representation
Provides utility classes for querying application specific paths
- Host: GitHub
- URL: https://github.com/robtimus/application-path
- Owner: robtimus
- License: apache-2.0
- Created: 2022-09-03T14:21:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-09T15:26:30.000Z (about 1 year ago)
- Last Synced: 2024-11-17T06:41:51.955Z (about 1 year ago)
- Topics: application, java
- Language: Java
- Homepage: https://robtimus.github.io/application-path/
- Size: 521 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# application-path
[](https://github.com/robtimus/application-path/actions/workflows/build.yml)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Aapplication-path)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Aapplication-path)
[](https://snyk.io/test/github/robtimus/application-path)
Provides utility classes for querying application specific paths.
For user data or configuration, platform independent applications tend to use `/.` regardless of the platform. While this works fine on Linux, on Windows (and to a lesser extend macOS), this is messy. This library makes it easy to use a single API and still use platform specific paths. As a result, on Windows the user's own `AppData\Roaming` or `AppData\Local` folder will be used.
Currently, only the path to store user data or configuration is supported. This will use the following paths:
* `$HOME/.` or `$HOME/./` for Linux and Unix
* `$HOME/Library/Application Support/` or `$HOME/Library/Application Support//` for macOS
* `%HOME%\AppData\Roaming\`, `%HOME%\AppData\Roaming\\`, `%HOME%\AppData\Local\` or `%HOME%\AppData\Local\\` for Windows
To retrieve the path for an application's user data or configuration, simply call `ApplicationPath.userData`:
```
Path userData1 = ApplicationPath.userData("My App");
// userData1 is $HOME/.My App on Linux, %HOME%\AppData\Roaming\My App on Windows
Path userData2 = ApplicationPath.userData("My Organization", "My App");
// userData2 is $HOME/.My Organization/My App on Linux, %HOME%\AppData\Roaming\My Organization\My App on Windows
```
To use `%HOME%\AppData\Local` on Windows, add the `LOCAL` option:
```
Path userData1 = ApplicationPath.userData("My App", UserDataOption.LOCAL);
// userData1 is $HOME/.My App on Linux, %HOME%\AppData\Local\My App on Windows
Path userData2 = ApplicationPath.userData("My Organization", "My App", UserDataOption.LOCAL);
// userData2 is $HOME/.My Organization/My App on Linux, %HOME%\AppData\Local\My Organization\My App on Windows
```
Note that the `userData` methods will not create any files or directories. It is the responsibility of the caller to create the path as necessary. This can usually be done using `Files.createDirectories`.