路径问题
在javaweb运行需要读取配置文件时可能会出现路径读取错误的问题
小编是通过静态代码块读取数据库的信息时出现的问题
static {
FileReader in=null;
Properties properties=new Properties();
try {
in=new FileReader("jdbc.properties");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("找不到文件路径!");
}
try {
properties.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("文件无法读取!");
}
setUrl(properties.getProperty("url"));
setPassword(properties.getProperty("password"));
setUsername(properties.getProperty("username"));
}
但是这样发现无法找到文件路径,一开始小编通过
System.getProperty("user.dir")
得到项目工作目录,得到D:\Program Files\eclipse这玩意,小编不相信啊,what are you弄啥呢?不应该是web服务器的目录嘛?&#