JAVA-Exception in thread “main“ java.io.FileNotFoundException

JAVA-Exception in thread “main“ java.io.FileNotFoundException,第1张

JAVA-Exception in thread “main“ java.io.FileNotFoundException Exception in thread “main” java.io.FileNotFoundException

发现找不到指定文件

写下面这块代码读取文件时发现找不到jdbc文件

public class PropertiesTest {
    public static void main(String[] args) throws Exception {
        Properties pros = new Properties();

        FileInputStream fis = new FileInputStream("jdbc.properties");
        //加载流文件
        pros.load(fis);

        //获取
        String name = pros.getProperty("name");
        String password = pros.getProperty("password");
        System.out.println("name = " + name + ",password" + password);
    }

}

最后发现需要添加文件的绝队路径,举例 如我的文件是这个路径

E:\IdeaProjects\studyProject\src\Chapter11\
public class PropertiesTest {
    public static void main(String[] args) throws Exception {
        Properties pros = new Properties();

        FileInputStream fis = new FileInputStream("E:\IdeaProjects\studyProject\src\Chapter11\jdbc.properties");
        //加载流文件
        pros.load(fis);

        //获取
        String name = pros.getProperty("name");
        String password = pros.getProperty("password");
        System.out.println("name = " + name + ",password" + password);
    }

}

这样就没问题啦。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5523452.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存