Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>Properties</code> uses "\" as an escape character. As you read the values in, the "\" character is been stripped off, meaning, rather then the value being <code>C:\pers\nick</code> as you would expect, it is actually coming out as </p> <pre><code>C:pers ick </code></pre> <p>The stranger thing is, if you had saved the configuration file with <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#store%28java.io.OutputStream,%20java.lang.String%29" rel="nofollow"><code>Properties.store</code></a> this should have being resolved automatically for you (the value in the properties file would look something like <code>C\:\\pers\\nick</code></p> <p>So, if I create a properties that looks like:</p> <pre><code>results.download.location = C:\pers\nick results.download.location2 = C\:\\pers\\nick </code></pre> <p>Then read it using</p> <pre><code>public static void main(String[] args) { InputStream is = null; try { is = new FileInputStream("Test.properties"); Properties p = new Properties(); p.load(is); System.out.println(p.getProperty("results.download.location")); System.out.println(p.getProperty("results.download.location2")); } catch (Exception e) { e.printStackTrace(); } finally { try { is.close(); } catch (Exception e) { } } } </code></pre> <p>I get the output of...</p> <pre><code>C:pers ick C:\pers\nick </code></pre> <p>Now, if I write the file using...</p> <pre><code>String value = "C:\\pers\\nick"; // Value has to be escaped for assignment... System.out.println("Value to be written = " + value); OutputStream os = null; try { os = new FileOutputStream("Test.properties"); Properties p = new Properties(); p.setProperty("results.download.location2", value); p.store(os, ""); } catch (Exception e) { e.printStackTrace(); } finally { try { os.close(); } catch (Exception e) { } } </code></pre> <p>The properties file looks like...</p> <pre><code>results.download.location2=C\:\\pers\\nick </code></pre> <p>Now this should allow the user to enter a value of "C:\pers\nick" and if you write it correctly, it will be automatically escaped.</p> <p>From the sounds of things, you've hand coded the properties file ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload