This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I have developed a small swing application (as a .jar file) where I store (persist) data in an ASCII files. I read from these files while launching and using the application. My question is 1. To avoid cluttering of files and to prevent these files to be edited outside my application, can I somehow keep all the files encrypted, say, as '.dat' file. I tried using java.util.zip classes but could not go very far. 2. Is there any other better way to handel this situation. Thanks a lot. Ashish PS: I tried but could not find answer in the archives. [ October 15, 2003: Message edited by: Ash Gupta ]
Gregg, Data in these ASCII files will be added/updated/deleted as the applicaiton is being used. Moreover, files will be created in not existing. Actually I am using data files to persist data instead of a database. With these requirments, can I still make them as part of jar files?
Just because you encrypt the file and/or change the extension, it doesn't stop someone from opening them with an editor and modifying them. Unless there is sensitive info like passwords, I wouldn't encrypt them. Maybe make the file extension something other than .txt though just to keep the casual user from opening them easily. If someone wants to edit them, they will. Both my freeware Swing apps store config info in a plain text file (a .properties file) - if someone wanted to edit them by hand, they could (in fact, I do it all the time while testing). My code just has the logic to know what to do if a property is not found or if the file itself is not found. Brian [ October 16, 2003: Message edited by: Brian Pipa ]
Thanks Brian, As I mentioned earlier, my sole purpose to zip/encrypt the files is to avoid cluttering all over. On same note, where do you store the 'config' file for your applications? Is it part of the jar file? Also can the config file be updated through application, say, user want to change some configuration. Thanks Ashish
Joined: Sep 29, 2003
As I mentioned earlier, my sole purpose to zip/encrypt the files is to avoid cluttering all over.
If you want to zip them up, you certainly can. I have worked with the java zip classes and found them pretty easy to use. You could create a zip file and store all your config files in the zip file locally.
On same note, where do you store the 'config' file for your applications?
My apps are distributed as executable jar files so I chose to store the config files in the same dir as the .jar. I always hate installing apps that put their config files all ove the place. This way, all the program's files are in one dir - the dir the user chose to put the executable jar.
Is it part of the jar file?
No. The first time the app is run, it sees that there is no config file so it creates one with default values and saves it. Every time after that, it reads from the config file allready in place.
Also can the config file be updated through application, say, user want to change some configuration.
Yes. I wrote a ConfigProperties class that takes care of the reading and writing of the config so that as the user changes the configuration in hte program, it can be easily saved back to the config file. If you want to see my ConfigProperties class, I can let you see/have/use it. It's quite handy - I use it in both my apps. Brian