How to use relative paths
--- From Internet
InProgramData Files or resource files (e.g.) are often used. If an absolute path is used in a program, the program will lose flexibility. For example, our application directory is D: \ NECs, and the data directory is D: \ NECs \ database. If we use the data file, use the D: \ NECs \ database directory name. When our program is moved to drive C, an error occurs because the data directory is changed to c: \ NECs \ database. Therefore, we need to use the relative directory \ database.
We can use the java. util. properties class, which is a hashtable and stores many system attributes. Where:
......
Java. Home Java installation directory
Java. Class. Path Java class path
File. Separator file separator ("/" on UNIX)
User. dir user's current working directory
......
We can use the java. Lang. System Method getproperty (string key) to obtain the required properties.
Curdir = system. getproperty ("user. dir ");
Filebar = system. getproperty ("file. separator ");
The data directory in the above example can be expressed as curdir + filebar + "Database"