Properties-file with a relative path...

Hello everybody,
my question is as follows:
I have a directory-structure like below:
root_dir
|
-- source
|
-- classes
|
-- libs
|
-- xmlfiles
|
myproperties.propsIn words: my root_dir (is actually a subdirectory in my fs) contains folders like source (java-files), classes (class-files)... and a properties-file myproperties.props. The source-dir has subdirs like com/xyz/bla/Mainclass.java...
I want to load the properties-file from the main-class, but without using the absolute path. That's the way I do it at the moment:
Properties props = new Properties();
props.load(new FileInputStream("d:\\foo\\something\\root_dir\\myproperties.props"));But I don't want to write the whole path, because of portability (forget the \\ :) )!
How can I obtain the root_dir?
Thanx for helping!
Regards, Robert4

Well I was already working on a replacer for /../ stuff before I was pointed to the File class. Not the best code I've written, but works fine. Perhaps it could be of use to you.
    public void setCoordinatesFileURL(String coordFileURL)
        coordinatesFileURL=coordFileURL;
        //replace .. to get canonical path
        StringTokenizer st = new StringTokenizer(coordinatesFileURL,"/");
        String[] stringURL= new String[st.countTokens()];
        int teller=0;
        while(st.hasMoreTokens())
            String token=st.nextToken();
            if(!token.equals(".."))
                stringURL[teller]=token;
                teller++;
            else
                teller--;
        coordinatesFileURL="";
        for(int i=0; i<teller-1;i++)
            coordinatesFileURL+=stringURL[i]+"/";
        coordinatesFileURL+=stringURL[teller-1];
    }

Similar Messages

  • How to open a configurat​ion file with a relative path?

    I want to open a configuration file during the initialization of my application (first "state," u can say) and I am using "Open Config file.vi" and tried to pass the config file's path as "data\myconfig.ini" and the "File exists?" vi didn't give any error (simply, the output was "false") but the Open config File gave an error.
    If I pass an absolute path "D:\xyz\xyz\myconfig.ini" it works fine. Isn't it allowed to use "relative path" as I remember using it before for other tasks?
    I actually prefer to have this file in the "data" folder that my application's setup will create in the destination directory while installing the application, because it will be easy when I want to ask the user to open and edit it. Or, I would just put it in "C:\" which exists on all the windows computers, but then it would be too much open.
    Thanks ahead!
    Vaibhav
    Solved!
    Go to Solution.

    Relative paths have sometimes a meaning for command line tools (where a relative path gets appended to the current path, which usually is the executables directory).
    But for Windows GUI applications that makes not much sense. Windows also maintains a per process current path, but that path gets updated by several Windows APIs, one of them being the File Dialog. So whatever your user has last selected in any file dialog inside your application will from then on be the applciations current path. It should be clear that with such a braindamaged current path implementation it has basically no useful meaning, and LabVIEW consequently does not do path expansion, where relative paths are expanded by prepending them with the applications current path.
    Also LabVIEW uses mostly the Windows 32 Bit API, which does provide the current path implementation but does almost not use it in any of its file operations. The use of that feature is mostly reserved for the Windows shell API, which is a higher level API that can as best be described as a collection of various APIs that have been thrown together by whatever some MS developer felt at the moment. You can not by any means call it a designed API at all, and LabVIEW makes almost no use of it, as it needs lower level access, to make its operation similar in its working across all the platforms, LabVIEW can run on.
    So while you can work with relative paths inside your application (and actually should as much as possible to make your application not depend on a particular location) you should make that path absolute whenever you pass it to a function that actually accesses a file somewhere.
    Rolf Kalbermatter
    Message Edited by rolfk on 09-08-2009 11:31 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to load a .properties file by giving relative path in a JSP file.

    Hey guys,
    I'm trying to load a .properties file in a JSP using relative path...
    It is not taking the properties file..
    What is the problem...?
    Any solution..?
    Thanks a lot.

    Yes I tried that also.
    Your path was something like this ?
    http://localhost:8080/Database/a.properties ?
    Whether this path will change after client installation ? if no then what's the problem ?
    For client side installation how you are going to set your conf directory for your application ?
    You are not going to give client installation page ?which will have all the values to be set like conf path. database,user name(s),log folder,temp folder etc ? Why you are keeping everything on server ?
    Check if this is useful,
    String context = request.getContextPath();
    String rmtAdd = request.getRemoteAddr();
    String host = request.getRemoteHost();
    out.println("http://"+rmtAdd+context+"<BR>");
    out.println("http://"+host+context);
    "http://"+rmtAdd+context
    Edited by: kanad on Jan 12, 2008 1:29 PM

  • AppleScript / saving file to a relative path

    Hello everybody,
    I would like to make a script that saves current file to a relative path. For example: I have a psd opened file (that is in pictures/01/image01.psd) and I need to save it one level up as a JPEG ( pictures/image01.psd).
    This is what I've tried, however, the result is that the file is saved in the root of Photoshop - in applications folder:
    tell application "Adobe Photoshop CS6"
              set myFile to "./"
              set myOptions to ¬
                        {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte} ¬
      save current document in file myFile as JPEG with options ¬
      myOptions appending no extension without copying
    end tell
    Thanks in advance

    I need it 1 level up no matter where - since there will be different folders.
    Thanks!

  • PCK installation : misssing  aii.properties file in the given path

    Hi all,
    i am doing installation for PCK from PCK installation guide, i want a aii.properties file in the given path  usr/sap/<sapsid>/JC00/j2ee/cluster/server0 but it's missing
    can anyone knows from where i can get this file .
    thanks

    You find it on the installation DVD. You can also use the aii.properties from an XI installation.
    Regards
    Stefan

  • Properties file not deploys the path correctly

    Hello,
    I am deploying a Web dynpro application with properties file.
    One of the properties contains a path that I am later using in my app, something like this:
    PATH =
    myserver
    folder1
    folder2
    The problem is that after deployment I see this property in the config tool with one backwards slash like this:
    PATH = \myserver
    older1\folder2\
    And I need it with
    in my app.
    Even after applying a custom value: "
    myserver
    folder1
    folder2
    " and clearing the cache it doesn't seem to work.
    I know that in java \ states that the char afterwards is special so
    realy means \ so I even tried to deploy this : PATH =
    myserver
    folder1
    folder2
    but got the same behaviour.
    Any idea why is this happening?

    Hi,
    Since you have already tried using four slashes and it didnt work.
    I thot putting space in between will give different result.
    For me, the four slash option shud have worked.
    Ashu

  • Updating properties file with values containing characters like slash (/)

    Hi,
    I am writing a java class that would create/update properties file. I am passing a string that contains colons. e.g. a path like
    http://xyz.com
    I am using the java.util.Properties.setProperty(String arg0, String arg1) method to set the key value and the java.util.Properties.store(OutputStream arg0, String arg1) to create/update the properties file.
    The resulting property file contains the value as http\://xyz.com
    A slash preappended to the colon.
    I do not want this slash to be preappended.
    How can I achieve that?

    If you don't want this escaping to happend, then you don't want to be using java.util.Properties. Those define the file format in a certain way that includes escaping those characters.
    If you don't want this, you'll have to write them using normal Writers (and read them using Readers) with your own parsing/storing logic added.

  • Bring in another .psd file with the clipping path

    Okay, this client has a very odd request. They want a collage of images put together in one file and they want the clipping paths to be attached. Then it's to be saved as an eps file. I'd like to do this in InDesign and am going to be posting this same question there as well. I like that in InDesign, the clipping path stays attached to the image when you move it. However, is there a way to do this in Photoshop? I don't know how to bring .psd files into Photoshop along with their clipping paths. If there is a way to do this, is there a way to link the clipping path to the layer so that when I move the individual layers, the clipping path moves with it?
    Help would be greatly appreciated! Thank you!

    In Photoshop "Clipping Path" is a special kind of Path and limited to one per image and not linked to one Layer.
    A work-around to combine multiple images with individual Clipping Paths into one psd file with a combined Clipping Path could be
    • applying the Clipping Paths as Vector Masks to the images (flattened to one Layer or converted to a Smart Object each),
    • combining them and after positioning/transforming/…
    • copy/pasting the individual Vector Masks into one new Clipping Path.

  • Properties files with Tomcat 4.0.1

    I'm having trouble finding properties files using Class.getResourceAsStream
    Properties props = new Properties();
    try {
      props.load(Class.class.getResourceAsStream("/Database.properties"));
    catch (IOException e) {
      //error reading from stream
    }The above code works fine on several web server (including Tomcat 3.2.3), but fails on Tomcat 4.0.1 - the server takes around 50 seconds to return a response, then throws a StackOverflowError. The properties file is in WEB-INF/classes.
    Has anybody else had the same problem?

    Thanks for the reply Guido.
    However, I can't use the ServletContext to load the files I'm after, because the code is part of the data tier and should not be dependent upon the controller (in fact I have no reference to the ServletContext).
    If I can't use Class.getResourceAsStream in Tomcat 4, does that mean that any third party APIs that rely on it will fail? - seems a little strange to me!
    The Tomcat 4.0 documentation says:
    "All unpacked classes and resources in the /WEB-INF/classes directory of your web application archive, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others."
    I would expect "All unpacked classes and resources" to include all unpacked resources (such as properties files)
    I've now managed to load the properties file using this code:
    props.load(new FileInputStream(getClass().getResource("/Database.properties").getFile()));(don't know why getResource should work when getResourceAsStream doesn't, but that's what appears to be happening).
    Now I have a new problem - loading a JDBC driver. I get:
    java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:120)
    when I call
    new OracleConnectionCacheImpl()
    but the class does exist, in a zip file (OracleThinClientJDBCDriver_901.zip) in WEB-INF/lib. It looks to me like the oracle code in the lib directory has been found by the ClassLoader, but that Class.forName does not work...eh?!?

  • Schema include with a relative path coming up relative to xml doc

    I have a main schema document that includes my other schema documents to make up the entire schema. All the documents are in the same default no namespace. All the includes are relative to the main schema doc (they are all in the same dir). I set the schemasource in the SAXParser to the main document. Then I try to parse and it isn't finding any of the included files. I have searched and searched these forums and found no answer.
    What i have tried is making an EntityResolver and when I print out the systemId in resolveEntity, it is printing out a location that is relative to the XML document that it being parsed, not a path relative to the main schema where all the schema files are. If i set the schemaLocation in the include to be the full path, it works fine. Why it is looking for them in the directory where the XML document is and not the schema?
    any help would be greately appreicated. Thanks!

    Probably because some standard says that what it is supposed to do. If you think it is wrong (and have a reference to some standards document to back up your opinion) you could complain to the people who maintain your parser.

  •       AMF Channel endpoint uri- relative path is prepended with http giving an invalid

    <?xml version="1.0" encoding="UTF-8"?>
    <services-config>
    <services>
    <service id="amfphp-remoting"
    class="flex.messaging.services.RemotingService"
    messageTypes="flex.messaging.messages.RemotingMessage">
    <destination id="amfphp">
    <channels>
    <channel ref="my-amfphp"/>
    </channels>
    <properties>
    <source>*</source>
    </properties>
    </destination>
    </service>
    </services>
    <channels>
    <channel-definition id="my-amfphp"
    class="mx.messaging.channels.AMFChannel">
    <endpoint uri="
    http://192.168.0.1/path/subpath/amfphp/gateway.php"
    class="flex.messaging.endpoints.AMFEndpoint"/>
    </channel-definition>
    </channels>
    </services-config>
    To access the remote object of flex I need to give the
    absolute path in URI.
    Is there any way to overcome this issue.
    I have tried with the relative path by putting the amfphp in
    root folder (i.e. htdocs), but flex component is still not working.
    I am using flex charts as a component and using php to
    connect with the database. Using remote objects I am fetching the
    values but due to path dependancy my application comes out with a
    major drawback.
    Can anyone please post some solution.

    "shivam_raj" <[email protected]> wrote in
    message
    news:glut03$9ug$[email protected]..
    > Giving dynamic IP is possible or not guys?
    Try looking at this example
    http://flexdiary.blogspot.com/2009/01/lazy-loading-tree-example-file-posted.html

  • Relative path for files

    hi all,
    I am making a small program that needs to store some of the users preferences in a text file. I want the text file to be in the jar when i am finished and in the same folder as the main class. I am having a problem though with writing to a reading the file in a relative path. when i use "args.txt" it reads to the c:\args.txt and not the folder in which the program runs. Same thing with "\\args.txt" and "/args.txt". Any help? Thanks! :)

    If your file is in the same directory as the program the relative path is simply the file name : "args.txt". Also possible is "./args.txt".
    Keep in mind though that you can't write to a file in a jar, and even reading it is more complicated than with the ordinary I/O classes.
    Look up the getResourceAsStream method in the API (I think it's a method of the ClassLoader class).

  • Problem with include and relative path in jsp

    Precompile jsp with wlappc in 9.2, I got the error "The include file was not found" when the jsp use <%@ include file="../includes/dataEntry/code_error.html" %>
              This code used to work with 8.1. I notice that someone has report the same problem with 9.0 and you have patch for it. Is it fix in 9.2 or do I require a patch as well?
              Thanks,
              Khuemy

    When you precompile, can you say "Keepgenerated=TRUE". It might help you track
              down the difference with the URL. You should only get a 404 error when the
              resource is not found at runtime, which is independant of when you compile. The
              difference should be in how the URL is compiled.
              Chris
              ali wrote:
              > I am using WLS 6.0 SP1, when I use relative path in <jsp:forward> in my JSPs
              > it forwards ok if I am using directly JSPs but if I am using pre-compiled
              > JSPs (and have proper servlet-mappings
              > in my web.xml), I get 404 error with the relative-path, if I change it to
              > absolute path with pre-compiled JSPs it forwards ok , then.
              > any ideas why this is so?
              > thanks,
              

  • How to set Path for a properties file

    Hi,
    I am using a SQL.properties file to load all my SQL statements to my EJB JDBC prepared Statement. I have placed the SQL.properties file in com.company.sql package. I have another SQL class in the same package which is loading the SQL.properties file to cache for future use. I am using the path as "SQL.properties" (the file name straight ) in the SQL class to access the properties file.
    I am using Sun App Server 7. To get access to this file I need to copy the SQL.properties file to the config directory of the app server instance. Otherwise it is not able to locate the file. I don't want to put the properties file in the config directory of the app server instance. Please help me, what path I have to give to access the file from the package itself, rather from the config directory of server instance.
    I think , some one who is doing localization can help me out here. They have to put the localized properties file to access the text out of it. Please help me. Thanks in advance.
    Thanks
    Amit

    I am using the propeties file to get the SQL statements. I have all the SQL query statement in the properties file. I am creating a preparedstatement after getting the statement from the properties file with the id like we do in ResourceBundle. If I keep the properties file in the config directory of the Sun App Server instance , then it is working fine. But If I don't keep it there, then it is giving me a file not found exception.
    My SQL class which is accessing the properties file are in same package (com.company.sql). But still it is not able to find the file. As suggested by you, I tried it by giving the path as com.company.sql.SQL. Still it did not found the file. The file is there inside the WEB-INF/classess/com/company/sql/.
    Thanks
    Amit

  • How to get InputStream from a file with absolute path?

    Hi, guys:
    If I have file with a absolute path that may be inside/outside
    my Eclipse plugin, I want to get an InputStream from it. It just keeps giving me null for "is":
    String absFilePath = "/D:/my_dir/.../sample_file.txt";
    InputStream is = getClass().getResourceAsStream(absFilePath);
    regards,

    Don't use resource as stream if you have an absolute path, use FileInputStream.

Maybe you are looking for

  • Voice Memos off iPhone 4s

    I have a large voice memo (30 minutes), recorded on 7/2/2012. Can't seem to get it off the iphone and into itunes. I have tried checking the box to "Include voice memos" & also emailing the memo but get the error that the memo is too long. Is there a

  • Random Line reading in text file

    I am trying to read a random line in a text file but every time i read it it reads first line of the file any one can help me what is the problem in the code is or provide me with a new code. BufferedReader in = new BufferedReader(new InputStreamRead

  • Safari crashing every time I open it

    Suddenly, Safari crashes every time that I open it.  Or, perhaps every time that I scroll a webpage using the trackpad? There are no outstanding software updates. I repaired disk permissions. I've restarted the computer. Still crashes every time. Her

  • PLD: BO on A/R Invoice

    Hi all, I have a customer who is trying to add a Back Order field to her A/R Invoice PLD. If you have any suggestions that would be helpful. Thanks! Best regards, Jeff Haldeman Support One

  • DMEE - Foreign Payments - Denmark - bulked debit

    Hello together, Currently I am facing a problem with foreign payment with the DMEE tree: DK_PAYMUL_DOMESTIC I copied it and use the fromat tree also for Foreign payments. The problem which occurs right now is, that the output file is not correct. The