Question: I have a `global.properties` file and have to define the file path inside this properties file.

```
SheetPath=C:\\Users\\test\\Automation-Scripts\\DataTable.xlsx

```

This is an absolute path but require a way to define a relative path that can be consumed while calling.

Answer: 
**Properties file:**

```
testPath=API_Files/duplicateToken.json

```

**Load the properties file:**

```
public static Properties readProperties = new Properties();
public static void loadPropertiesFile() {
    File propertiesFile = new File(location of properties file);
    try {
        FileInputStream fileInput = new FileInputStream(propertiesFile);
        readProperties.load(fileInput);
    } catch (Exception e) {
        Logger.LogError("Error in loading the Properties file" + e.getMessage());
    }
}

```

**Read the properties file and get absolute path:**

```
 String testPath = readProperties.getProperty("testPath").trim();
 File absolutePath =  new File(System.getProperty("user.dir") + testPath);
 System.out.println(absolutePath);

```

**Sample output:**

```
C:\Users\test\Automation-Scripts\duplicateToken.json

```
The properties file should be relative to classpath. You can create a "configs" folder at the level of src and use the below code to read the file. Refer [this](https://www.toolsqa.com/selenium-cucumber-framework/read-configurations-from-property-file/) for more explanation and techniques.

```
private Properties properties;
    private final String propertyFilePath= "configs//Configuration.properties";    
BufferedReader reader = new BufferedReader(new FileReader(propertyFilePath));
Properties properties = new Properties();
properties.load(reader);

```