Properties p = new Properties();
try {
//此处出错查找了许久,发现读取文件时,配置文件位置必须从src开始往下写才能找到文件,否则提示文件找不到或路径不对
File file = new File("src/com/hope/resource/msgbean.properties");
System.out.println("file="+file);
FileInputStream fin = new FileInputStream(file);
System.out.println("fin = "+fin);
p.load(fin);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(p.getProperty("str"));
}
查找文件时用流读取文件时,查找位置从项目开始,所以必须将查找到属性文件从src开始输入文件路径。
try {
//此处出错查找了许久,发现读取文件时,配置文件位置必须从src开始往下写才能找到文件,否则提示文件找不到或路径不对
File file = new File("src/com/hope/resource/msgbean.properties");
System.out.println("file="+file);
FileInputStream fin = new FileInputStream(file);
System.out.println("fin = "+fin);
p.load(fin);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(p.getProperty("str"));
}
查找文件时用流读取文件时,查找位置从项目开始,所以必须将查找到属性文件从src开始输入文件路径。