Solved

Java Properties Class: getProperty() question

Posted on 2003-11-03
2
459 Views
Last Modified: 2008-03-03
Hi

Im using Properties class to read my configuration.ini file which contains variables for my program.

And one of the variables is for a directory path:

directory = C:\some\directory

now the problem is: if i use getProperty

String path = prop.getProperty("directory");

it stripped the "\" off !!

I supposed i could add another \ in the configuration.ini. But is there any other way to do it better? Because someone might go to configuration.ini file and change the directory manually without knowing another "\" required to make it work.

Help..

And im really sorry bout the small point, im running out of points here :(

0
Comment
Question by:JaZziD
2 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 25 total points
ID: 9670317
directory = C:\\some\\directory

OR

directory = C:/some/directory
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 9670478
Quick explanation as to why:

When you deal with Strings the \ character indicates that we want to escape the next character, and the only valid escape characters are
\b \t \n \f \r \" \' \\
It looks as if you may have b, t, n, n or r as the first character of your directory, so you wouldn't have got an error from it.

As suggested by TimYates, you can use the escaped version of the \ character: \\ or, what I believe to be the more common approach, use the Unix style path seperator of /.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question