Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default Help needed to load relative path of file

    I am new to java. I am trying to load a properties file from the root level of my project in workspace. I am using below code to get the relative path of my file

    File appPath = new File(System.getProperty("user.dir"));
    Properties props = new Properties();
    props.load ( new FileInputStream ( new File (appPath +"/xyz.properties" )));

    but this loads the current working directory of eclipse and not the path of my workspace where properties file is kept.I do not want to change the current working directory of eclipse physically as the project will be used on other systems as well. I just want to get it done thru coding. Can you please help me out.

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

    Default

    You just use "./" for this.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Unhappy

    Din't work

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

    Default

    It works correct. You just don't understand how it works.
    This path "./" to point current folder, where you run code. Can you show structure your project?
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    PartScrubberProject
    |--Manufacturerinfo.properties
    |--src
    |--EPCClassLoader

    It will not work even if i add more slashes because
    the logger is searching for properties file at below location
    C:\eclipse-jee-ganymede-SR1-win32\eclipse.\Manufacturerinfo.properties (The system cannot find the file specified)
    The current directory setup in eclipse is default. I don't want to change this.

    Thanks for helping.

  6. #6
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    I tried below code as well but it returns NullPointerException

    InputStream in = EPCClassLoader.class.getResourceAsStream("Manufact urerinfo.properties");

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

    Default

    see
    Java Code:
    import java.util.*;
    import java.io.*;
    
    public class LoadProperties {
    	public static void main(String[] arg) throws Exception {
    		Properties props = new Properties();
    		props.load(new FileInputStream(new File("./main.properties")));
    		System.out.println(props);
    	}
    }
    It is structure my project.
    Java Code:
    ReportProject/main.properties
    ReportProject/src/LoadProperties.java
    That is all.
    Skype: petrarsentev
    http://TrackStudio.com

  8. #8
    patilmm9 is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default In Eclipse Still Iam getting error

    InvalidDescriptionException = java.io.FileNotFoundException: .\main.properties (The system cannot find the file specified)

    I simpley added
    Properties props = new Properties();
    props.load(new FileInputStream(new File("./main.properties")));
    System.out.println(props);


    Please reply

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

Similar Threads

  1. How to use a relative path for a file?
    By kipade in forum SWT / JFace
    Replies: 0
    Last Post: 02-28-2011, 06:37 AM
  2. Add a jar file to Java load path at run time
    By marioneil in forum Advanced Java
    Replies: 5
    Last Post: 09-22-2010, 07:58 AM
  3. how to set relative path in jsp?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-02-2009, 08:20 AM
  4. Obtaining relative path outside of executable JAR
    By tjsaker in forum Advanced Java
    Replies: 1
    Last Post: 11-14-2008, 06:48 AM
  5. Load class file which resides in local path c:\
    By praveen.kb in forum Advanced Java
    Replies: 2
    Last Post: 08-12-2008, 01:55 PM

Tags for this Thread

Posting Permissions

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