Results 1 to 6 of 6
  1. #1
    Gnanam is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default to find the workspace path at runtime to write the file

    Hi All,
    this is my first post in this forum..
    I have a Struts project deployed in tomcat webapps. User Sign in details are configured in a xml file and are validated by reading the xml file..The xml file is in the path WEB-INF/classes/com/files/user.xml...
    when a new user has to be added his/her details has to be written in the same user.xml file..I read the the file using
    getClass().getClassLoader().getResourceAsStream("c om/files/user.xml");

    To write the file using filewriter if I have to give the full path without hardcoding it.
    For eg.
    D:/SDE3.0/workspace/project/WebContent/WEB-INF/classes/com/files/user.xml
    when I tried to get this path URL using getClass().getClassLoader().getResource("com/files/user.xml") , i get
    C:/Program Files/SDE3.0/tomcat-5.5.16/webapps/Request/WEB-INF/classes/com/files/user.xml

    Please suggest me how to solve this issue or is there way to find the workspace path at runtime so that I can avoid hardcoding of this path.
    Thanks in advance
    Regards,
    Gnanam

  2. #2
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    Check your struts-config.xml make sure you give all the data source names on that including user.xml

  3. #3
    Gnanam is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default

    Hi

    Thanks for your reply.I am new to struts.This is my first Struts project.
    I haven't made any entry for data source in struts-config.xml.
    Could you please tell me if I have to use like this
    <data-source key="dataSource">
    <set-property property="user.xml" value="C:/Program Files/SDE3.0/tomcat-5.5.16/webapps/Request/WEB-INF/classes/com/files/user.xml" />
    or
    <data-source key="dataSource">
    <set-property property="user.xml" value="D:/SDE3.0/workspace/project/WebContent/WEB-INF/classes/com/files/user.xml" />


    Pls reply me and pardon me if my question is so lame.
    Thanks in advance
    Gnanam

  4. #4
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    For make it simple please keep the user.xml file in web-inf directory. And let me to know the IDE you have been use.

  5. #5
    Gnanam is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default

    I am using SDE3.1(Eclipse)
    Ok I ll keep user.xml in web-inf dir.
    But will getClass().getClassLoader().getResourceAsStream("u ser.xml") load it or will it look in web-inf /classes dir.

  6. #6
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    Actually its automatically load it. If any problem to do it download and use Struts consol third party Struts tool

Similar Threads

  1. how to write onto a file
    By mirage_87 in forum New To Java
    Replies: 6
    Last Post: 09-08-2009, 04:54 PM
  2. Regular expression for file path
    By ravian in forum New To Java
    Replies: 3
    Last Post: 01-25-2008, 09:24 PM
  3. File Write Error
    By vikain in forum Advanced Java
    Replies: 5
    Last Post: 01-02-2008, 05:38 AM
  4. Write unicode into file
    By vata2999 in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 04:04 PM
  5. Help with write file in java
    By mathias in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •