Where should my application save its data files?

Every operating system has a preferred default folder for saving data files generated by an application. On my Mac, it is users/<username>/library/application support/<application name>. On Windows, it is somewhere inside Documents and Files.
Is there a way to determine this folder in Java?
If at all possible I want my application to automatically load its data files at start up, and save them on exit, without prompting the user for a location. But the default folder appears to be the folder containing the jar, which is not the best choice for the platform.
-Ron.

There is a system property called user.home that will point you to the right folder. You'll still have to do a bit of platform specific code if you want to it correctly, though. Here's a method I use in my private toolbox (SysInfo is also private, but i guess you'll see what is does from the code):
     * Returns the appropriate working directory for storing application data. The result of this method is platform
     * dependant: On linux, it will return ~/applicationName, on windows, the working directory will be located in the
     * user's application data folder. For Mac OS systems, the working directory will be placed in the proper location
     * in "Library/Application Support".
     * <p/>
     * This method will also make sure that the working directory exists. When invoked, the directory and all required
     * subfolders will be created.
     * @param applicationName Name of the application, used to determine the working directory.
     * @return the appropriate working directory for storing application data.
public static File getWorkingDirectory(final String applicationName) {
        final String userHome = System.getProperty("user.home", ".");
        final File workingDirectory;
        switch (SysInfo.getPlatform()) {
            case LINUX:
            case SOLARIS:
                workingDirectory = new File(userHome, '.' + applicationName + '/');
                break;
            case WINDOWS:
                final String applicationData = System.getenv("APPDATA");
                if (applicationData != null)
                    workingDirectory = new File(applicationData, "." + applicationName + '/');
                else
                    workingDirectory = new File(userHome, '.' + applicationName + '/');
                break;
            case MACOS:
                workingDirectory = new File(userHome, "Library/Application Support/" + applicationName);
                break;
            default:
                return new File(".");
        if (!workingDirectory.exists())
            if (!workingDirectory.mkdirs())
                throw new RuntimeException("The working directory could not be created: " + workingDirectory);
        return workingDirectory;
    }

Similar Messages

  • When I save a pages document as a pdf and then try to email the document, it loads as an application octet-stream dat file instead of a pdf. What's happening?

    When I save a Pages document as a pdf and then try to email the document, it loads as an application octet-stream dat file instead of a pdf and recipients can't open it. Some load correctly, but about half don't load as a pdf. What's happening?

    Hi mjmonck-
    Which email provider are you using? There are different solutions possible for different providers. Yahoo is having trouble with attachments, outside of any Firefox issue. I've seen a Google user fix this by manually adding the mail URL to their ad block program- which mistakenly perceived the webmail page as an advertisement.
    Hope this helps.

  • Where does Stylus save its data for Logic

    I just got Stylus and am using Logic 8. I am wondering where Stylus saves its data that Logic accesses. I have searched my whole G5 and can't seem to find it anywhere.

    Do a spotlight search for the "SAGE" folder - the RMX library, expansion packs and user saved multi's are all in there.

  • Looking for answers on XMP files - where should they be stored as sidecar files?  With the original raw file or in a separate folder?

    Looking for answers on XMP files - where should they be stored as sidecar files?  With the original raw file or in a separate folder?
    Relatively new user of Adobe LR5 and PS CC, about a year old. 
    If they should be stored somewhere beside the folder that contains the originals, where and how to change the settings?
    If I choose to write metadata to the original files, is that sidecar files or does the XMP file show separately?
    To be honest, I usually find a video and I cannot figure this out.  I have never received an answer on any of my questions by the way. 

    Hi there,
    You answered a prior question from me so I wanted to reach out to you about this.   I just need a step by step on how, if possible, to View LRCC on my MacBookPro when the main interface is on my iMac

  • Where I hv to SAVE the ERROR file, got in RETURN table of BAPI for ME51N?

    Hi Experts,
    Pls. clarify one of my simple doubt that, the functional owner have been asked to create a ERROR file(has given name as PR_ERROR_FILE), for the encountered errors, while uploading the data from flat file into Data Base for Purchase requisation-ME51N tx.
    So, am thinking to upload by using a BAPI_PR_CREATE.
    1) So, I can catch the ERRORS in RETURN table, then , pls. let me  now that, Where I hv to SAVE/Create this ERROR file-PR_ERROR_FILE? Is it C drive?
    2) Is I hv to SAVE as a Flat file format?
    (the functional guy, is not availble)
    Functinal guy words are,
    For any errors that occur, those should be written out to an error file so that users can review and correct.
    The error file should be name PR_ERRORS_FILE
    thanq

    No this will be save in the aplication server only...on the given path so any one can read it and rectify the error.

  • Where can I find the Reminders data file in Mountain Lion?

    Hi,
    Does anyone know where I can find the data file for the reminders in Mountain Lion?  When I recently synced my iPad to iMac it deleted the 50+ reminders that were on the iMac.  I have done hourly backups with time machine but would like to know where to go to find these to reinstate them. 
    Also, does anyone knows how to turn off the reminders sync as I'm not using iCloud and there does not appear to be any option to sync reminders in iTunes?
    Thanks a bunch!!

    Hi,
    in JDeveloper 11 the deployment is in the project properties. I am not sure they are written to the file system anymore
    Frank

  • How to Create a Button for Reader Users to Save XML Data File?

    The "Submit via Email" tries to launching the local email software, like outlook express. But public computer tends to use internet emails.
    I am thinking of creating a button, allowing the reader users to save xml data filled in the form (same as the "submit via email" produces) somewhere.
    anyone has a clue?
    Thanks a lot!

    You could create the shortcut at one machine, then copy it to the target as part of the logon script. Note also that this line contains an error:
    "C:\Users\%userprofile%\Desktop\Org_chart_test.lnk"
    It should read:
    "%userprofile%\Desktop\Org_chart_test.lnk"

  • Where is the Application Sharing defaulttrace.trc file located?

    Hi,
    In a help document it says this:
    a.      Set the Application Sharing Server trace file (defaultTrace.trc) to severity info and try to start a new session.
    but where is the Application Sharing file located? or it means the J2EE defaultTrace file?
    Thanx in Advanced!
    Kind Regards,
    Gerardo J

    Hi Gerardo,
    Collaboration uses the logging mechanisms of the J2EE Engine. Therefore it is the defaultTrace.trc  under .../usr/sap/<SID>/Jxx/j2ee/cluster/serverX/log/ .
    Kind regards
    Klaus

  • I have an application on PXI 8146RT who save several data files in the comppact flash mémory. I am looking for the best solution to transfert thoses files to a host PC without stop my application. Can you help me?

    My application is not an RT application

    Your PXI-8146RT runs an FTP server, which could be leveraged to transfer files to a host PC while your application continues to run.
    There is an FTP client in MAX and several available for free on the internet. Alternately you can open a web browser such as Internet Explorer and type ftp://www.xxx.yyy.zzz to access the PXI's file system. Then just copy/paste the files you want.

  • Where does xcode 5 save the executable files that it creates?

    I already built my console application, and I can run it from xCode as well. Now I'd like to find the executable file it generates. I saw in an old tip in this forum that it's just to right-click the corresponding product item and select Show in Finder in the menu. However that option is disabled, as you can see in the picture below.
    I also tryied the bin\release\debug and it's not there as well.
    What am I doing wrong?
    Tks in advance,
    Mauro Assis

    I checked the Locations and they're default, as you can see below:
    Am I correct?
    Opening the default path in Finder:
    Do you think it should be here? Where?
    Tks again,
    Mauro

  • Where SHOULD the application support folder be?

    on My 2009 imac it is in the library folder. on my late 2008 MBP it is in the finder when I double click the hard drive, its just above "applications".

    The Applications folder should be at the top level of the hard drive.
    Not sure what you mean about the application folder being above "applications".

  • How do I reinstall an Adobe application from its .dmg file

    I have inadvertantly deleted the icon to open Adobe Dreamweaver, however I do have a .dmg copy of the application. How do I reinstall Dreamweaver from the .dmg file?

    Steph44 wrote:
    I have inadvertantly deleted the icon to open Adobe Dreamweaver
    Where? From the Dock or the Applicaitons folder?
    The Dock icons are "aliases" or "shortcuts" to the original files  or programs, in this case in your Applications folder.
    Just drag the Adobe Dreamweaver icon out of the Applications folder and position it on the Dock in the old location, it will make another "alias" and the original returns to the Application folder.
    If it's gone from your Applicaiotns folder, look in your Trash can and put it back in the Applicaitons folder
    If not there then open the DMG by double clicking on it and double clicking on the installer file to reinstall it.
    You'll have to update the program and likely enter your serial again.

  • ITunes cannot save its library file

    Since yesterday (Sun 4-Aug) I have been seeing this unfortunate message from iTunes:
    The iTunes library file cannot be saved. You do not have enough access priveleges for this operation.
    ***? the iMac had priveleges before then, for weeks. It has written dozens of CD tracks since then. It seems the ONLY file it cannot write is the Library File.
    All of the data is on a remote NAS unit. Loads of space. I have been adding my CD collection for months. Until now, of course. The few CDs since yesterday do not show in the listings after restarting iTunes. I can see that the album contents were copied to the same location as the Library File. It would seem the Library File is magical somehow.
    How do I fix this stupidity?

    I "fixed" this:
    changed the the Library's path to another <iTunes Media> directory
    copied the "unwriteable" library files to the new location
    pointed iTunes to the new location when it started.
    iTunes is functional again.
    For such a popular program iTunes is not very well designed or implemented. At least not the parts where I have an interest.

  • Where does Elements 10 store its catelog file

    I had 32gb on my mac hard disk. I asked elements 10 organiser to catelog my 10,000 photos. It ran through the process then aborted at the end. I have uninstalled Elements but I still have "lost" a load of disk space. I am thinking my organiser photo file is somewhere on my disk still ? Does anyone know where it is stored ? Thanks.

    The catalog shouldn't take up that much space unless you imported from iphoto, in which case your photos were all copied and in that case it's the copies, not catalog itself, that are taking up space. The actual catalog file location can be found by going to Help>System info in the organizer.

  • Where does the dock store its data

    I am trying to discover where the linkage is between the icon in the dock and the actual location of the resource. does anyone have that information?
    Thanks very much,
    Aunty

    Hi Auntie,
    /Users/YourUserName/Library/Preferences/com.apple.dock.plist
    Which save aliases to the real locations, like...

Maybe you are looking for

  • Analog 5.1 headphones & Optical Speake

    I have a Soundblaster X-Fi Platnium w/optional front panel. Is it possible to configure my Medusa 5. surround sound headphones to be plugged in and still get sound via the Optical Toslink to my digital speakers (configured analog though)? Additionall

  • Connect Sony Handycam DCR-SR42E & nothing happens

    Hi, We have just purchased the above video camera after speaking with both the Sony helpdesk in NZ and the Apple helpdesk and was told the camera would work with our ibook. Not that worried about importing the movies into imovie at this stage, just w

  • Positive surprise: PSE 4.0 came along with a 200+ page User Guide

    Today, when I got by regular mail my PSE 4.0 version, the box containing the Software contained also a User Guide of a little more than 200 pages. This is in contrast to the PSE 3.0 box that I got one year earlier: it contained only a 70-page "Gettin

  • Bug liquify with transparency

    Hi there. I found bug when I liquify some transparent layer. In liquify filter window all looks OK, BUT when filter done I got strange results - my transparent pixel (usually it's shadows) have something like stairs (and my shadow is little lighter).

  • Printing on a DVD with C6180 All-n-one

    My blank dvd's are labeled that they can be directly printed on with an HP Inkjet. Can I print on them with the C6180? If so, how? OS Windows 7 64bit.