This is part of a personal utility library I wrote. All you need is the file path, you can write to the directories normally thereafter.
// Detects operating system.
String opSys = System.getProperty("os.name").toUpperCase();
if (opSys.contains("WIN"))
system.os = OperatingSystem.WINDOWS;
else if (opSys.contains("MAC"))
system.os = OperatingSystem.MAC;
else if (opSys.contains("NUX") || opSys.contains("NIX"))
system.os = OperatingSystem.LINUX;
else if (opSys.contains("SOL"))
system.os = OperatingSystem.SOLARIS;
else
system.os = OperatingSystem.UNKNOWN;
// Detects the user's home directory.
system.homeDir = System.getProperty("user.home");
// Detects the user's active directory.
system.workingDir = System.getProperty("user.dir");
// Detects the path to the application directory.
switch(system.os)
{
case WINDOWS:
system.applicationDir = System.getenv("APPDATA");
break;
case MAC:
system.applicationDir = System.getProperty("user.home") +
"/Library/Application Support";
break;
default:
system.applicationDir = system.homeDir;
break;
}