启动java程序时,我试图加载外部file.properties,但这不会加载文件。我的桌面上有这个程序和file.properties。这不是web应用程序。
我还将pc上的环境变量配置为类路径和路径,但是当我运行程序时,它不会看到它们
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系统。
请帮帮我
发布于 2017-05-19 12:51:18
您必须使用正确(完整)路径名,如:
String filePath = APLHOME + File.separator + "file.properties";
or
String filePath = System.getenv("APLHOME") + File.separator + "file.properties"; 在打开文本文件以查看类路径方面没有任何机制。
发布于 2017-05-19 12:58:37
FileNotFoundException基本上只是意味着您的文件不存在,或者您提供了错误的路径。
你需要提供绝对路径。否则Java将无法找到它。
//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"));https://stackoverflow.com/questions/44070091
复制相似问题