Showing posts with label property. Show all posts
Showing posts with label property. Show all posts

18 August 2011

How to solve common problems with load , save , get and set properties in java?

Solution based on java 6 (but it should apply for all version since 1.0)

So you setup your propeties like:

paths.secret.loverslist= C:\\mySecrets\\loverlist.txt

or something similar  but when your application load/save properties and start use them then you discover result are crap and produce bunch of weird characters instead and cause program to work in akward way (Exceptions, JVM crash and other fireworks) and you think:

WTF java ,what's wrong with you ?

most problems are caused by encoding issues* because you need to knows that
java.util.Properties loads properties files using the ISO-8859-1 encoding so your file need to be saved in that format or shit hit the fan.

in rest cases are typo error like path issue (like using \ instead of \\) , so do double check or ask somebody to check for you.

and remeber properties file need be saved using   ISO-8859-1 encoding !!!!

(Source: http://download.oracle.com/javase/6/docs/api/java/util/Properties.html )
  *  from my experience  66% encoding , 33% typo error, 1% others

11 April 2011

System properties for java 6 (System.getProperty("key") list of keys)

List of keys with  their description
(key = explanation

Key Description of Associated Value
java.version =  Java Runtime Environment version
java.vendor =  Java Runtime Environment vendor
java.vendor.url =  Java vendor URL
java.home =  Java installation directory
java.vm.specification.version =  Java Virtual Machine specification version
java.vm.specification.vendor =  Java Virtual Machine specification vendor
java.vm.specification.name =  Java Virtual Machine specification name
java.vm.version =  Java Virtual Machine implementation version
java.vm.vendor = Java Virtual Machine implementation vendor
java.vm.name = Java Virtual Machine implementation name
java.specification.version =  Java Runtime Environment specification version
java.specification.vendor =  Java Runtime Environment specification vendor
java.specification.name =  Java Runtime Environment specification name
java.class.version =  Java class format version number
java.class.path =  Java class path
java.library.path =  List of paths to search when loading libraries
java.io.tmpdir =  Default temp file path
java.compiler = Name of JIT compiler to use
java.ext.dirs =  Path of extension directory or directories
os.name = Operating system name
os.arch = Operating system architecture
os.version = Operating system version
file.separator = File separator ("/" on UNIX)
path.separator = Path separator (":" on UNIX)
line.separator =  Line separator ("\n" on UNIX)
user.name =  User's account name
user.home = User's home directory
user.dir = User's current working directory

source: oracle.com