Solved

Java Properties Class: getProperty() question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
return in catch statement 1 40
countAbc challenge 9 49
json format text only 4 65
Java - Why doesn't this JFrame work 3 16
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

708 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

17 Experts available now in Live!

Get 1:1 Help Now