Results 1 to 7 of 7
  1. #1
    nn12 is offline Member
    Join Date
    Sep 2008
    Posts
    85
    Rep Power
    0

    Default Getting the exact location of the config files

    I have two questions regarding my java project. We are making use of a jar file which takes the location of the configuration.txt as one of the parameter and the output of that is an image file which we need to store on temp basis.

    The configuration file is placed inside the WebContent folder.

    Here is what I am doing currently

    Java Code:
    String configFile = "/configuration.txt";
    String outFile = "/images/output.png";
    String path = request.getSession().getServletContext().getRealPath("/");
    outFile = path+outFile;
    configFile = path+configFile;
    Question:
    1. Is this the best way to get the location of the configFile?
    2. As the o/p of this program is an image file, whats the best place to store it temporarily.

    My code is currently reading the conf file from
    D:\Documents and Settings\username\My Documents\project\abc\.metadata\.plugins\org.eclip se.wst.server.core\tmp0\abc.ear\abc.war\configurat ion.txt

    and storing the image at
    D:\Documents and Settings\username\My Documents\project\abc\.metadata\.plugins\org.eclip se.wst.server.core\tmp0\abc.ear\abc.war\images\out put.png

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    I can offer other solution you task.
    You can use system param, which point where locate your configuration file.
    When you start app you will check param and if it not exist you throw exception that "you must to set system param". In app you can get this param as follow
    Java Code:
    String path = System.getProperty("CONFIG_PATH");
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    nn12 is offline Member
    Join Date
    Sep 2008
    Posts
    85
    Rep Power
    0

    Default

    I would rather avoid another system property here :( Let me know if there is any other better solution

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Is it that you do not want to use relative paths? Or that you want to store the file in a specific location relative to system root?

  5. #5
    nn12 is offline Member
    Join Date
    Sep 2008
    Posts
    85
    Rep Power
    0

    Default

    Yes, I am open to relative paths.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    So in that case, create files like
    Java Code:
    File file = new File("myFile.txt");
    //or
    File file = new File("myLocalFolder/someNestedFolder/myFile.txt");
    Its relative, because you are not giving an explicit path, everything will be relative to whatever the project root is.

  7. #7
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Although I thinks the best way this use system property, This will allow improve flexible and scalable а your project.
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. Help 2 exact classes
    By JavaProgrammerO in forum New To Java
    Replies: 0
    Last Post: 12-04-2010, 09:48 AM
  2. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 03:53 PM
  3. Replies: 3
    Last Post: 01-18-2010, 05:13 AM
  4. location provider returns no location
    By sandeeprao.techno in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-24-2009, 09:54 AM
  5. Adding property or config files to a project
    By anacapa in forum Eclipse
    Replies: 3
    Last Post: 02-03-2009, 07:34 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
  •