首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java项目和外部文件fil.properties

java项目和外部文件fil.properties
EN

Stack Overflow用户
提问于 2017-05-19 12:25:50
回答 2查看 85关注 0票数 0

启动java程序时,我试图加载外部file.properties,但这不会加载文件。我的桌面上有这个程序和file.properties。这不是web应用程序。

我还将pc上的环境变量配置为类路径和路径,但是当我运行程序时,它不会看到它们

代码语言:javascript
复制
String filePath = "file.properties";
Properties data = new Properties();
    try{

        FileInputStream stream = new FileInputStream(new File(filePath));
        data.load(stream);
        execute(args,data);

    } catch (FileNotFoundException e) {
        e.printStackTrace();

这是一个错误:

java.io.FileNotFoundException: file.properties (Impossibile .)在java.io.FileInputStream.(FileInputStream.java:137) at it.applications.AssCitRice.ParseXmlSct.(ParseXmlSct.java:42) at it.applications.AssCitRice.ParseXmlSct.main(ParseXmlSct.java:286) log4j的java.io.FileInputStream.open(原生方法):没有为记录器(it..applications.AssegniCitRicezionePresentazione.ParseXmlSct).找到任何附加程序log4j :警告请正确初始化log4j系统。

请帮帮我

EN

回答 2

Stack Overflow用户

发布于 2017-05-19 12:51:18

您必须使用正确(完整)路径名,如:

代码语言:javascript
复制
String filePath = APLHOME + File.separator + "file.properties";
or
String filePath = System.getenv("APLHOME") + File.separator + "file.properties"; 

在打开文本文件以查看类路径方面没有任何机制。

票数 0
EN

Stack Overflow用户

发布于 2017-05-19 12:58:37

FileNotFoundException基本上只是意味着您的文件不存在,或者您提供了错误的路径。

你需要提供绝对路径。否则Java将无法找到它。

代码语言:javascript
复制
//The below will work great as long as the file exists in that path.
FileInputStream stream = new FileInputStream(new File("C:/test.txt"));

//This will however not work
FileInputStream stream = new FileInputStream(new File("/test.txt"));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44070091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档