我有有代码现在如何读取属性从不同的位置,文件中JAVA
public class SourceHandler {
String PrpPath = null;
Properties prop = null;
public Properties loadConfigProperties() {
try {
System.out.println("Propertiess " +PrpPath);
InputStream in =new FileInputStream(new File(PrpPath));
prop.load(in);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
,并在不同类的主要方法,
public static void main(String[] args) throws ParserConfigurationException,
Exception {
try {
SourceHandler conf = new SourceHandler();
conf.setProperties("C:/config.properties");
Properties p = conf.loadConfigProperties();
System.out.println("Done");
} catch (DOMException dome) {
// TODO: Add catch code
dome.printStackTrace();
}
,如果我跑sourcehandler.java类的代码,它示出了在线路零指示字例外,prop.load(in);
堆栈跟踪:
显示java.lang.NullPointerException 在DecryptEncryptSource.SourceHandler.loadConfigProperties(SourceHandler.java:98) 在DecryptEncryptSource.SourceHandler.updateCofigDestn(SourceHandler.java:151) 在DecryptEncryptSource.MainClass.main(MainClass.java:27)
您可以加入的确切路径'字符串'你在用吗? – Berger
是Berger,这是从主要方法传递的确切路径“C:\ config.properties”,我也可以通过sop打印。 – Jeelan
向我们展示如何从'main'方法传递它,这是至关重要的。 –