Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Relative path issue with Context path struts

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Relative path issue with Context path struts

    Hi All,

    I have 2 projects -

    1. ProjecttContent - {context path ---> /hardware/xl/abc/content}
    |--------------WebContent
    |-----------ODSFileContent
    |---------------- content.xml


    and ProjectWeb - {context path ---> /hardware/xl/abc}
    |-------------- JavaSource
    | -------------- package com.xl.abc.data
    | ---------- ContentData.java


    Now, in ContentData.java i need to get content.xml file to do further operation which is in ProjectContent project.

    In ContentData.java ------

    I am getting contextpath from request. which returns /hardware/xl/abc since this java file is in ProjectWeb.

    As content.xml is in ProjectContent, so appended /content to context path which is returned from request in ContentData.

    i.e. request.getContextPath(); returns /hardware/xl/abc

    BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(request.getContextPath()+"/content.xml"));

    [3/30/11 21:53:06:328 IST] 0000003e SystemErr R java.io.FileNotFoundException: \hardware\xl\abc\content\content.xml (The handle is invalid.)
    [3/30/11 21:53:06:343 IST] 0000003e SystemErr R at java.io.FileInputStream.open(Native Method)
    [3/30/11 21:53:06:343 IST] 0000003e SystemErr R at java.io.FileInputStream.<init>(FileInputStream.jav a:129)

    Please let me know how to get access to content.xml which is in ProjectContent from ContentData.java in ProjectWeb

    Thanks,
    Chinnu


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Relative path issue with Context path struts

    I suggest using: System.out.println(request.getContextPath()+"/content.xml"); to see what the full path looks like.

    The exception suggests that it cannot locate the file. Maybe try putting the full path in like so:

    BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("\\hardware\\xl\\abc\\content\\content.xml"));

    See if this works then we can take it from there.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Exception in jpcap path
    By vrp in forum Exceptions
    Replies: 0
    Last Post: February 10th, 2011, 12:04 AM
  2. Shared library path
    By sateesh.b in forum Java Native Interface
    Replies: 3
    Last Post: May 14th, 2010, 12:12 AM
  3. Program to print current directory path to the console
    By JavaPF in forum Java Programming Tutorials
    Replies: 1
    Last Post: October 9th, 2009, 01:59 PM
  4. how to get full path name from realtive path
    By priyanka3006 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 10th, 2009, 05:28 AM
  5. [SOLVED] How to a set java class path?
    By captjade in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2009, 07:40 AM

Tags for this Thread