Java Load File Location?

Discussion in 'Java' started by RigasMinho, Nov 20, 2006.

  1. RigasMinho

    RigasMinho Guest

    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?
    RigasMinho, Nov 20, 2006
    #1
    1. Advertising

  2. RigasMinho wrote:
    > 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
    Andreas Wollschlaeger, Nov 20, 2006
    #2
    1. Advertising

  3. > avoids the backslash escaping disease!

    ha ha! good one :)
    Jean-Francois Briere, Nov 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Dalessandro
    Replies:
    0
    Views:
    582
    Luke Dalessandro
    Jan 15, 2006
  2. zxo102
    Replies:
    0
    Views:
    396
    zxo102
    Aug 1, 2006
  3. saiho.yuen
    Replies:
    3
    Views:
    393
    kaeli
    Sep 14, 2004
  4. John Bailo

    IE7 shows location even if location=no

    John Bailo, Jan 19, 2007, in forum: Javascript
    Replies:
    4
    Views:
    161
    OmegaJunior
    Mar 11, 2007
  5. hehehe

    adf java and <location></location>

    hehehe, Jul 6, 2009, in forum: Javascript
    Replies:
    1
    Views:
    95
    Evertjan.
    Jul 6, 2009
Loading...

Share This Page