读取properties文件问题
我的代码如下:
Properties prop = new Properties();
InputStream is=getClass().getResourceAsStream("/hibernate.properties");//hibernate.properties放就放在当前路径;
try{
prop.load(is);
}catch(Exception e){
e.printStackTrace();
}
hibernate.properties内容如下:
hibernate.dialect = org.hibernate.dialect.SQLServerDialect
hibernate.connection.driver_class = com.microsoft.jdbc.sqlserver.SQLServerDriver
hibernate.connection.url = jdbc:microsoft:sqlserver://localhost;databasename=hibernate
hibernate.connection.username = sa
hibernate.connection.password = sa
错误如下:java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load(Unknown Source)
为什么提示读取不到文件啊?
Properties prop = new Properties();
InputStream is=getClass().getResourceAsStream("/hibernate.properties");//hibernate.properties放就放在当前路径;
try{
prop.load(is);
}catch(Exception e){
e.printStackTrace();
}
hibernate.properties内容如下:
hibernate.dialect = org.hibernate.dialect.SQLServerDialect
hibernate.connection.driver_class = com.microsoft.jdbc.sqlserver.SQLServerDriver
hibernate.connection.url = jdbc:microsoft:sqlserver://localhost;databasename=hibernate
hibernate.connection.username = sa
hibernate.connection.password = sa
错误如下:java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load(Unknown Source)
为什么提示读取不到文件啊?
...全文
相关推荐
spring无法读取properties文件数据问题详解
Spring 无法读取 properties 文件数据问题详解Spring 框架在读取 properties 文件数据时可能会遇到一些问题,本文将对这些问题进行详细的解释和解决。
java读写properties文件,解决系统找不到指定路径,解决写入后读取正常,但文件数据未更新问题
在处理Properties文件时,可能会遇到几个常见的问题,包括找不到指定路径、读取正常但文件数据未更新的情况。以下是对这些问题的详细解答。首先,让我们解决“系统找不到指定路径”的问题。
java读写properties文件,解决系统找不到指定路径,解决写入后读取正常,但文件数据未更新问题
然而,有时可能会遇到一些常见问题,比如系统找不到指定的Properties文件路径、写入后读取显示正常但实际文件数据未更新等。下面我们将详细讨论这些问题及其解决方案。
详解Java项目中读取properties文件
例如,上述示例展示了如何在静态初始化块中使用反射读取文件。这种方式允许我们在不创建类实例的情况下读取properties文件。总结一下,Java中读取properties文件的常见方法包括:1.
java读取properties属性文件
我们可以通过以下步骤来读取properties文件:1.


Web 开发
