Why not save the file in the official application directory? Then it does not matter what the current directory is. (See getAppUserDataDirectory .)
System.Directory has other useful directories and useful file system utilities. It is cross-platform in the sense that it knows where things should go according to your OS.
Reasoning:
If you save working data in the same directory as the executable file, only the one who has write permissions in this directory can run your program correctly. Only the superuser can write to directories like /usr/local/bin , and only the administrator can write to C:\Program Files\ . Using the User Application Catalog, anyone can run the application because the application data directory is user-specific and can be writable, so this is good practice.
Personally, I donβt like applications to clutter up my main user area with configuration data, but you want applications to offer my user area as the first suggestion to save some of my own content ( getHomeDirectory ). I suggested the user application data directory because you proposed the executable directory, so it sounded like configuration data.
source share