Where's a good place to store SQLite databases in Java Applications?
I'm developing my first CLI Application in Java and I've made the decision to go with SQLite for t开发者_如何学Gohe database back-end.
I intend for the application to be cross-platform and need some guidance on where to actually store the database on users' computers. Obviously I can't store it in the .jar file right because if they need to update the application they'll lose their data correct? Or is there a workaround?
Maybe the easiest location is to put it in some sub-directory of the system property "user.home". You can get it with
System.getProperty("user.home")
In unix-like systems, for a user called 'bill' this usually maps to ~bill. In windows systems, it maps to something like C:\Document and Settings\bill
So, if you program is called "amazing", you look for and create a directory like
new File
(
new File(System.getProperty("user.home")),
".amazing"
);
精彩评论