XML problems reading file in another directory

Discussion in 'Java' started by simon_s_li@hotmail.com, Oct 25, 2005.

  1. Guest

    Hi,

    I am new to XML and I am trying to read an XML file 3 directory levels
    up.

    In the jsp I am setting the src to "..\..\..\directory\file.xml" and
    I've tried "../../../directory/file.xml". Both these methods don't
    seem to be able pick the xml file up.

    If I put the file in the same directory it works ok.

    By the way, I cannot move the file to the same directory as lots of
    other files read this file in the current directory.

    Can you help?? What am I doing wrong??

    Regards
    Simon
     
    , Oct 25, 2005
    #1
    1. Advertising

  2. Roedy Green Guest

    On 25 Oct 2005 03:05:43 -0700, wrote, quoted or
    indirectly quoted someone who said :

    >In the jsp I am setting the src to "..\..\..\directory\file.xml" and
    >I've tried "../../../directory/file.xml". Both these methods don't
    >seem to be able pick the xml file up.


    You might try dumping the CWD. You might be surprised.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 25, 2005
    #2
    1. Advertising

  3. Oliver Wong Guest

    <> wrote in message
    news:...
    > Hi,
    >
    > I am new to XML and I am trying to read an XML file 3 directory levels
    > up.
    >
    > In the jsp I am setting the src to "..\..\..\directory\file.xml" and
    > I've tried "../../../directory/file.xml". Both these methods don't
    > seem to be able pick the xml file up.
    >
    > If I put the file in the same directory it works ok.
    >
    > By the way, I cannot move the file to the same directory as lots of
    > other files read this file in the current directory.
    >
    > Can you help?? What am I doing wrong??


    If I take your explanation literally, it seems like the correct path
    should be "..\..\..\file.xml", as you say it's 3 directories up, not 2
    directories up, and 1 directory "sideways".

    Have you tried moving the file just one directory up and doing
    "..\file.xml" to see if you're suffering from some sort of "off by 1" error?

    Have you tried creating a file object pointing to the current directory
    and programmatically going up via .getParentFile()?

    - Oliver
     
    Oliver Wong, Oct 25, 2005
    #3
  4. Roedy Green Guest

    On Tue, 25 Oct 2005 21:36:44 GMT, "Oliver Wong" <>
    wrote, quoted or indirectly quoted someone who said :

    > "..\..\..\directory\file.xml"


    Don't forget that in Java strings, \ has to be doubled.
    and in regexes quadrupled to get a literal \.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Oct 26, 2005
    #4
    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.

Share This Page