So, das hier wäre eine rudimentäre plattformabhängige Lösung. Immerhin kann man in Java automatisiert bis zum Homeverzeichnis des Users kommen. Code: String homedir = System.getProperty("user.home"); String osname = System.getProperty("os.name"); String pathsep = System.getProperty("path.separator"); String configpath; // Achtung, inkompatibel mit Multiuser-9x. // user.home evaluiert unter 9x meistens zu ?:\WINDOWS, nur nicht in Muliusersystemen, wo es zu ?:\WINDOWS\PROFILES\<Username> evaluiert. if ("Windows 95" == osname || "Windows 98" == osname) configpath = methodPostedByDFYX().toString() + pathsep + "myapp.ini"; // Keine Ahnung, wie Vista heißt. "Windows Vista" klingt plausibel. // Achtung, dieser Code muß für jede Locale angepaßt werden, weil Microsoft die Ordnernamen übersetzt! if ("Windows NT" == osname || "Windows 2000" == osname || "Windows XP" == osname) configpath = homedir + pathsep + "Dokumente und Einstellungen" + pathsep + "myapp" + pathsep + "myapp.ini"; elseif ("Mac OS" == osname) // Wir ignorieren Mac OS 9 und früher. configpath = homedir + pathsep + "Library" + pathsep + "Preferences" + pathsep + "myapp.ini;" else // Wir gehen davon aus, daß alle anderen OSe *nix sind configpath = homedir + pathsep + ".myapp" + pathsep + "myapp.ini"; Achtung, user.home hat unter Windows einen Bug.
String homedir = System.getProperty("user.home"); String osname = System.getProperty("os.name"); String pathsep = System.getProperty("path.separator"); String configpath; // Achtung, inkompatibel mit Multiuser-9x. // user.home evaluiert unter 9x meistens zu ?:\WINDOWS, nur nicht in Muliusersystemen, wo es zu ?:\WINDOWS\PROFILES\<Username> evaluiert. if ("Windows 95" == osname || "Windows 98" == osname) configpath = methodPostedByDFYX().toString() + pathsep + "myapp.ini"; // Keine Ahnung, wie Vista heißt. "Windows Vista" klingt plausibel. // Achtung, dieser Code muß für jede Locale angepaßt werden, weil Microsoft die Ordnernamen übersetzt! if ("Windows NT" == osname || "Windows 2000" == osname || "Windows XP" == osname) configpath = homedir + pathsep + "Dokumente und Einstellungen" + pathsep + "myapp" + pathsep + "myapp.ini"; elseif ("Mac OS" == osname) // Wir ignorieren Mac OS 9 und früher. configpath = homedir + pathsep + "Library" + pathsep + "Preferences" + pathsep + "myapp.ini;" else // Wir gehen davon aus, daß alle anderen OSe *nix sind configpath = homedir + pathsep + ".myapp" + pathsep + "myapp.ini";
Foren-Regeln