我不能用下面來加載屬性文件片斷加載屬性文件在java中
URL configURL = null;
URLConnection configURLConn = null;
InputStream configInputStream = null;
currConfigProperties = new Properties();
try {
String configPropertiesFile = getParameter("propertiesFile");
if (configPropertiesFile == null) {
configPropertiesFile = "com/abc/applet/Configuration.properties";
}
System.out.println("configPropertiesFile :"+configPropertiesFile);
configURL = new URL(getCodeBase(), configPropertiesFile);
configURLConn = configURL.openConnection();
configInputStream = configURLConn.getInputStream();
currConfigProperties.load(configInputStream);
} catch (MalformedURLException e) {
System.out.println(
"Creating configURL: " + e);
} catch (IOException e) {
System.out.println(
"IOException opening configURLConn: "
+ e);
}
獲得java.io.FileNotFoundException異常。
我想這將工作=> configPropertiesFile =「src/com/abc/applet/Configuration.properties」 – Juvanis 2013-03-19 11:24:33
大概這是一個從遠程服務器加載的小程序?還是你想從類路徑中讀取?無論哪種方式,請嘗試'ClassLoader.getResourceAsStream'方法。 – 2013-03-19 11:25:49
@ bmorris591 - classpath – happy 2013-03-19 11:26:26