8 Replies Latest reply: Nov 20, 2012 5:43 PM by baftos RSS

    Where do you store Properties files?

    ryvantage
      Hello,

      I am trying to determine the best location to store a properties file. I am going to deploy a small JWS app that needs to store properties and the default CWD for JWS apps is system32 (according to this S.O. thread: http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java). That clearly won't work...

      I just need a good place to hide the properties file. I could access the System property user.home and go to the Application Data folder, but that is a Windows-only solution (according to this thread: http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java)

      Any suggestions? Thanks.
        • 1. Re: Where do you store Properties files?
          rp0428
          >
          I am trying to determine the best location to store a properties file
          >
          Have you considered using Preferences instead of properties?
          http://docs.oracle.com/javase/6/docs/api/
          >
          public abstract class Preferences
          extends Object

          A node in a hierarchical collection of preference data. This class allows applications to store and retrieve user and system preference and configuration data. This data is stored persistently in an implementation-dependent backing store. Typical implementations include flat files, OS-specific registries, directory servers and SQL databases. The user of this class needn't be concerned with details of the backing store.
          • 2. Re: Where do you store Properties files?
            ryvantage
            rp,

            I was looking at Preferences, yes. But it seemed more complicated than I needed.

            I'll give it another look.
            • 3. Re: Where do you store Properties files?
              rp0428
              >
              I was looking at Preferences, yes. But it seemed more complicated than I needed.
              >
              No - they are more powerful that properties and are persistent but for the basics they are just as simple as properties
              http://docs.oracle.com/javase/1.5.0/docs/api/java/util/prefs/Preferences.html

              See this article and examples
              http://www.javacodegeeks.com/2011/09/use-javautilprefspreferences-instead-of.html
              >
              The Preferences API that is provided JDK can be used to solve this typical problem. Preferences work just like properties but they are persistent unlike Properties
              >
              Or this one
              http://www.vogella.com/articles/JavaPreferences/article.html
              • 4. Re: Where do you store Properties files?
                gimbal2
                ryvantage wrote:
                rp,

                I was looking at Preferences, yes. But it seemed more complicated than I needed.
                Yet you had to make a forum post about the alternative you picked. Makes you think, doesn't it? :)
                • 5. Re: Where do you store Properties files?
                  ryvantage
                  Ok, so the Preferences was definitely what I needed at the time. Thank you for that suggestion, RP. But I am now faced with the need to store Objects for later use (different app).

                  In past projects, I just pulled up the "user.home" System variable and navigated to (or created) "Application Data" folder, which is no good for Mac (and Linux I assume).

                  Preferences is great because you don't need to worry about location, but it cannot do Serialized Objects, only primitives and strings. So, what would you do to store Objects?

                  I already know about ObjectInputStream and Serialization. I just need a good, cross-platform way to hide the files.

                  What would you do?

                  Edited by: ryvantage on Nov 11, 2012 9:30 PM
                  • 6. Re: Where do you store Properties files?
                    ryvantage
                    Just curious if anyone has a solution to this problem. I'm still looking for the answer.

                    Where would you store application data in a cross-platform manner in a Java app?
                    • 7. Re: Where do you store Properties files?
                      EJP
                      If it's read-only, put it in the Jar file and access it as a resource.
                      • 8. Re: Where do you store Properties files?
                        baftos
                        06/07/2012  08:32 PM    <DIR>          .
                        06/07/2012  08:32 PM    <DIR>          ..
                        03/06/2012  12:10 PM    <DIR>          .android
                        12/03/2012  08:27 AM    <DIR>          .exe4j4
                        04/04/2012  03:15 PM    <DIR>          .yawcam
                        27/10/2012  11:48 AM    <DIR>          Contacts
                        17/11/2012  01:18 PM    <DIR>          Desktop
                        28/10/2012  05:15 PM    <DIR>          Documents
                        20/11/2012  02:40 PM    <DIR>          Downloads
                        13/11/2012  03:16 PM    <DIR>          Favorites
                        11/07/2012  07:05 AM    <DIR>          Links
                        23/07/2012  06:13 AM    <DIR>          Music
                        17/09/2012  08:45 AM    <DIR>          Pictures
                        11/07/2012  07:05 AM    <DIR>          Saved Games
                        11/07/2012  07:05 AM    <DIR>          Searches
                        06/07/2012  08:32 PM    <DIR>          temp
                        11/07/2012  07:05 AM    <DIR>          Videos
                        03/03/2012  10:41 PM    <DIR>          workspace
                        To be honest, I would do like other java apps do in my "user.home". Just forget about AppData and stick your stuff in a directory there. All the directories starting with "." there are for applications that are java related.

                        Edited by: baftos on Nov 20, 2012 6:43 PM