Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Java Properties Class: getProperty() question

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 71
What's wrong with this code? 4 26
difference between sorce folder and folder in eclipise 3 28
Notify sent to other threads in Java 9 33
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 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