路径问题
private void test8(){
System.out.println(System.getProperty("user.dir"));
}
private void test7() throws FileNotFoundException, IOException {
URL path =this.getClass().getResource("/db.properties");
try {
File file = new File(path.toURI());
FileInputStream in = new FileInputStream(file);
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
private void test6() throws FileNotFoundException, IOException {
URL path =this.getClass().getResource("db.properties");
try {
File file = new File(path.toURI());
FileInputStream in = new FileInputStream(file);
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
private void test5() throws IOException {
InputStream in=this.getClass().getResourceAsStream("/db.properties");
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
}
private void test4() throws IOException {
InputStream in=this.getClass().getResourceAsStream("db.properties");
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
}
private void test3() throws IOException {
InputStream in=this.getClass().getClassLoader().getResourceAsStream("db.properties");
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
}
private void test2() throws IOException {
String path=this.getServletContext().getRealPath("/WEB-INF/classes/db.properties");
FileInputStream in = new FileInputStream(path);
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
}
private void test1() throws IOException {
InputStream in=this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.properties");
Properties props = new Properties();
props.load(in);
System.out.println(props.getProperty("age"));
}