【问题标题】:I am trying to access config.properties file but unable to access. Can anyone help me?我正在尝试访问 config.properties 文件但无法访问。谁能帮我?
【发布时间】:2015-11-26 11:31:03
【问题描述】:
  package pageObjects;

  import java.io.FileInputStream;

  import java.io.InputStream;
  import java.util.Properties;


 public class ReadProperty {

public static void main(String[] args) throws Exception {


    Properties prop = new Properties();
    String fileName = "config.properties";
    InputStream input = new FileInputStream(fileName);

    prop.load(input);


    System.out.println(prop.getProperty("UserName"));
    System.out.println(prop.getProperty("Password"));

}

}

得到如下错误:

线程“主”java.io.FileNotFoundException 中的异常: config.properties(系统找不到指定的文件)在 java.io.FileInputStream.open(Native Method) 在 java.io.FileInputStream.(FileInputStream.java:138) 在 java.io.FileInputStream.(FileInputStream.java:93) 在 pageObjects.ReadProperty.main(ReadProperty.java:16)

【问题讨论】:

  • 您将 config.properties 文件放在哪里?

标签: java selenium-webdriver


【解决方案1】:

程序无法打开与config.properties文件的连接,可能有两个原因:

  1. 文件不存在。
  2. 其名称或路径不正确。

我猜这不是第一个选项,所以你可以尝试用文件的完整路径更改String fileName = "config.properties";

如果文件不在您正在执行程序的同一文件夹中,并且您没有指定完整路径,它将找不到它。因此,无论您的工作目录如何,您都可以始终确保程序能够找到它。

【讨论】:

  • 欢迎您@PardeepKochhar,如果它适合您,请点击绿色对勾将其选为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-31
相关资源
最近更新 更多