Solved

Java Properties Class: getProperty() question

Posted on 2003-11-03
2
458 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 82
egit plugin on eclipse 8 37
Windows 10 IE Certificate Issue 10 41
servlet example issue 6 30
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now