gpt4 book ai didi

java - 从配置读取器文件读取 config.property 文件时出现文件路径问题

转载 作者:行者123 更新时间:2023-12-02 11:50:47 25 4
gpt4 key购买 nike

从保存在名为 ExcelFiles 的其他文件夹中的 Excel 中读取数据,其中我有我的 congif.property,config.reader 将从中读取数据,部分代码如下所示:-

try
{
File filepath=new File("./InterviewPrep/ExcelFiles/congif.property");
FileInputStream fileaccess= new FileInputStream(filepath);

//C:\Users\Pratibha\workspace\InterviewPrep\ExcelFiles\congif.property //working fine

prop=new Properties();
prop.load(fileaccess);

System.out.println(prop.getProperty("username"));
}

当我使用文件路径时 - "./InterviewPrep/ExcelFiles/congif.property"
我收到错误 filenotfoundexception 但当我使用路径 -"C:\Users\Pratibha\workspace\InterviewPrep\ExcelFiles\congif.property" 时,代码执行成功。

为什么我在 "./InterviewPrep/ExcelFiles/congif.property" 这个文件路径中遇到错误?

最佳答案

尝试使用以下代码:

System.getProperty("user.dir")

关于java - 从配置读取器文件读取 config.property 文件时出现文件路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47886969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com