windows 8 - Java System.getProperty("user.home") directory missing separator -


whenever user enters "~" argument, program replaces system.getproperty("user.home").

after debugging, see replaces "~" "c:userssoulbeaver" , not "c:/users/soulbeaver".

going through previous questions incorrect user.home folders, found out java tries fetch path

hkey_current_user\software\microsoft\windows\currentversion\explorer\shell folders\

however, i'm using windows 8 , there seemingly nothing wrong:

at point i'm assuming java "eats" backslash... how prevent happening?

update

since code requested, here is. taken allen holub's solving java's configuration problem

/**  * every enum element in array, treat keys[i].name() key  * , load associated value following places (in order):  *  * <ol>  *     <li>a -d command-line switch (in system properties)</li>  *     <li>if no -d value found, environment variable same name key</li>  *     <li>if no environment found, default stored in enum element itself</li>  * </ol>  *  * value must identify existing directory in file system, ,  * file representing location can retrieved {@link #directory(enum)}.  *  * @param keys values() array associated enum that's using class.  * @throws illegalstateexception if given key doesn't have value associated  *          or if value doesn't identify existing directory.  */ public locationssupport(t[] keys) throws illegalstateexception {     stringbuilder logmessage = new stringbuilder("loaded environment/-d properties:\n");      try {         (t element : keys) {             string how = "???";             string key = element.name();              string value;             if ((value = system.getproperty(key)) != null)                 how = "from system property (-d)";             else if ((value = system.getenv(key)) != null)                 how = "from environment";             else if ((value = element.defaultvalue()) != null)                 how = "from default. mapped from: " + value;              if (value != null)                 value = value.replaceall("~", system.getproperty("user.home"));              if (value == null || value.isempty())                 throw new illegalstateexception("value " +key +" cannot null or empty.");              file location = new file(value);              createlocationifnecessary(location, element.createifnecessary());              if (!location.isdirectory())                 throw new illegalstateexception("location specified in "                         +key                         +" (" +asstring(location) +") "                         +"does not exist or not directory.");               dictionary.put(key, location);              logmessage.append("\t");             logmessage.append(key);             logmessage.append("=");             logmessage.append(asstring(location) );             logmessage.append(" (");             logmessage.append(how);             logmessage.append(")\n");         }     } {         if (log.getallappenders() instanceof nullenumeration)             system.err.println(logmessage);         else             log.info(logmessage);     } } 

it's failing @ trying locate default location config:

public enum places implements locations {     config ("~/config"),     home   ("~"),     tmp    ("~/tmp", true),      term_store     ("~/tmp/indices/term_store/",     true),     resource_store ("~/tmp/indices/resource_store/", true),     person_store   ("~/tmp/indices/person_store/",   true); 

i using java 1.7.0_13 , intellij idea 12.1.3

you using regular expression based replacement. in replacement pattern java regexes, '\' character special. need pass user home dir through matcher.quotereplacement() before using replacement pattern (as covered in javadoc relevant method).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -