public static String getPath() {
String path = "";
Properties prop = new Properties();
try {
InputStream in = ImageURL.class.getClassLoader().getResourceAsStream("jdbc.properties");
prop.load(in);
path = prop.getProperty("admin.path");
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return path;
}
String path = "";
Properties prop = new Properties();
try {
InputStream in = ImageURL.class.getClassLoader().getResourceAsStream("jdbc.properties");
prop.load(in);
path = prop.getProperty("admin.path");
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return path;
}

本文介绍了一个Java示例程序,该程序通过加载`jdbc.properties`文件来获取路径设置。具体步骤包括使用`ImageURL.class.getClassLoader().getResourceAsStream()`方法定位配置文件,然后利用`Properties`类进行读取和解析。

被折叠的 条评论
为什么被折叠?



