Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Added information about Windows versions newer than Vista because they also have UAC.
Source Link

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This method works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Windows Vista or newer may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This method works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This method works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Windows Vista or newer may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 
deleted 3 characters in body
Source Link
Botz3000
  • 39.8k
  • 8
  • 107
  • 128

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This mythologymethod works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This mythology works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This method works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 
added 879 characters in body
Source Link
Cheok Yan Cheng
  • 42.8k
  • 143
  • 504
  • 966

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This mythology works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This mythology works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

I usually store in user data directory, with sub directories of application name followed by application version.

public static String getUserDataDirectory() { return System.getProperty("user.home") + File.separator + ".jstock" + File.separator + getApplicationVersionString() + File.separator; } 

I had been using the following code for 3 years. This mythology works quite well either in Windows, Linux or Mac.

Please note that, in Windows, never store it in Program Files, as UAC in Vista may give you a lot of trouble.

Remember put a dot in-front of your application name, so that it will become a hidden folder in Linux.

Good thing by using this methology is that, you are not limited your self in storing primitive value only. Instead, you may save the entire object state to the disk by using xstream

For example :

public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; } 
Source Link
Cheok Yan Cheng
  • 42.8k
  • 143
  • 504
  • 966
Loading