Java Load File Location?

R

RigasMinho

I have this: Simple java code that loads in a properties file or an INI
file.

Same thing - compiles and works:

Properties defaultProps = new Properties();
FileInputStream in = new FileInputStream("Test.properties");
defaultProps.load(in);
in.close();

Here's the deal though - it only works if the test.properties file is
located in the same directory as the java file.

meaning d:\Javafiles\Properties.java -the folder javafiles has also the
file Test.Properties in the directory as well.

Is it possible to put the Test.properties file in say the C: drive and
call upon it that way?

I tried this:
FileInputStream in = new FileInputStream("c:\Test.properties");
but i get errors.

Any ideas?
 
A

Andreas Wollschlaeger

RigasMinho said:
I have this: Simple java code that loads in a properties file or an INI
file.

Same thing - compiles and works:

Properties defaultProps = new Properties();
FileInputStream in = new FileInputStream("Test.properties");
defaultProps.load(in);
in.close();

Here's the deal though - it only works if the test.properties file is
located in the same directory as the java file.

meaning d:\Javafiles\Properties.java -the folder javafiles has also the
file Test.Properties in the directory as well.

Is it possible to put the Test.properties file in say the C: drive and
call upon it that way?

I tried this:
FileInputStream in = new FileInputStream("c:\Test.properties");
but i get errors.

Any ideas?

Remember to double backslashes when used in a String literal,
"c:\\Test.properties" should work. Maybe it's even simpler to use a
forward slash : "C:/Test.properties" - avoids the backslash escaping
disease!

HTH
Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top