无法从Java类读取属性文件

时间:2019-04-30 23:01:58

标签: java properties filereader

(java的新手)

我正在尝试从该类中读取“ Config.properties”和“ OR.properties”文件。我相信我的道路是正确的。

Config.properties

  

\ Users \ krunalshah \ Documents \ workspace \ BankingAutomation_dataDrivenDesignApproach \ src \ test \ resources \ properties \ OR.properties

OR.properties

  

\ Users \ krunalshah \ Documents \ workspace \ BankingAutomation_dataDrivenDesignApproach \ src \ test \ resources \ properties \ Config.properties

但是我正在追随异常。

堆栈跟踪

  

线程“ main”中的异常java.io.FileNotFoundException:\ Users \ krunalshah \ Documents \ workspace \ BankingAutomation_dataDrivenDesignApproach \ src \ test \ resources \ properties \ Config.properties(无此类文件或目录)

项目体系结构 enter image description here

完整代码

at java.io.FileInputStream.open0(Native Method)

at java.io.FileInputStream.open(FileInputStream.java:195)

at java.io.FileInputStream.<init>(FileInputStream.java:138)

at java.io.FileInputStream.<init>(FileInputStream.java:93)

at com.dhartiRathod.rough.TestProperties.main(TestProperties.java:18)```

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

导入java.util.Properties;

公共类TestProperties {

//test the Object and config properties.



public static void main (String[] arg) throws IOException {





    //System.out.println(System.getProperty("user.dir")); ///Users/krunalshah/Documents/workspace/BankingAutomation_dataDrivenDesignApproach

    System.out.println(System.getProperty("user.dir"));

    Properties config = new Properties();

    Properties OR = new Properties();

    FileInputStream fis = new FileInputStream("\\Users\\krunalshah\\Documents\\workspace\\BankingAutomation_dataDrivenDesignApproach\\src\\test\\resources\\properties\\OR.properties");

    config.load(fis);



     fis = new FileInputStream("\\Users\\krunalshah\\Documents\\workspace\\BankingAutomation_dataDrivenDesignApproach\\src\\test\\resources\\properties\\OR.properties");

    OR.load(fis);



    System.out.println(config.getProperty("browser"));



    //driver.findElement(By.cssSelector(OR.getProperty("bmlBtn"))).click();

    System.out.println(OR.getProperty("bmlBtn"));

}

}

0 个答案:

没有答案