I want to save a specific file that the program uses at run time. To ensure this works on all my computers, I need to use the variable path so it's not looking for my directory on the other computer.
Fred Kleinschmidt wrote:What if the user has not set that environment variable ("TMP")? You need to check that the value returned by the env.get("TMP") is not null before you use it.
On every windows computer I have used, TMP was set correctly.
Correct me if I'm wrong but, TMP is a path setup by default by Microsoft.
All these should always be ready to use: http://www.askvg.com/list-of-environment-variables-in-windows-xp-vista-and-7/#comment-2444930
Fred Kleinschmidt wrote:You did not specify what platforms "all of my computers" were -as far as I knew, some could have been MAC, UNIX, or LINUX.
Right, sorry about that. I was referring to my Windows computers. Which is why I was asking about "Accessing Windows Environment Variables"
Fred Kleinschmidt wrote: anyway, the user can always remove an environment variable.
This is a possibility to keep in mind for when launching software towards a large range of people. I'm privately releasing for friends and family, most of which don't have administrator rights to mess with environmental variables.
Fred Kleinschmidt wrote:If the file in question is one that is a fixed input file for the program, the file should be included with the compiled code in a jar file that the user executes. Then there is no need to fool around with environment variables.
I read and write to this 1 specific file. If I package it with the jar, could I still write to it?
An alternative is to execute the program via a batch script that passes the file path to the program as a command line argument; This allows the user to place the file anywhere (such as wherever the program and batch file reside)
Paul Clapham wrote:If all of this discussion is in aid of your application being able to save a file, then you don't need any environment variables. Knute already mentioned how to deal with temporary files in Java, but if you want to save a file permanently (i.e. it will still be there the next time the application runs) then you can put it in the user's home directory. You can find a path to that directory like this:
Thanks. I'm looking into using the File.createTempFile() method