我正在尝试加载属性文件。这是我的结构
现在我正在尝试加载 test.properties 文件。但我越来越空了。我在这里怎么样
public class Test {
String workingDir = System.getProperty("user.dir");
System.out.println("Current working directory : " + workingDir);
File temp = new File(workingDir + "\\" + "test.properties");
String absolutePath = temp.getAbsolutePath();
System.out.println("File path : " + absolutePath);
Properties properties = null;
try {
properties = new Properties();
InputStream resourceAsStream = Test.class.getClassLoader().getResourceAsStream(absolutePath);
if (resourceAsStream != null) {
properties.load(resourceAsStream);
}
} catch (IOException e) {
e.printStackTrace();
}
System.exit(0);
} //end of class Test
该程序打印
Current working directory : D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration
File path : D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration\test.properties
但它没有从该路径加载属性文件。虽然它在那里。为什么我得到 null ?
谢谢
编辑 - - - - - - - - - - - - - - - -
String workingDir = System.getProperty("user.dir");
System.out.println("Current working directory : " + workingDir);
File temp = new File(workingDir, "test.properties");
String absolutePath = temp.getAbsolutePath();
System.out.println("File path : " + absolutePath);
try {
properties = new Properties();
InputStream resourceAsStream = new FileInputStream(temp);
if (resourceAsStream != null) {
properties.load(resourceAsStream);
}
} catch (IOException e) {
e.printStackTrace();
}
System.exit(0);
Current working directory : D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration
File path : D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration\test.properties
java.io.FileNotFoundException: D:\Personal Work\eclipse 32 Bit\workspace\Spring Integration\LS360BatchImportIntegration\test.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at com.softech.ls360.integration.BatchImport.main(BatchImport.java:57)