package com.spd.ORM;
import java.io.*;
import java.util.Properties;
public class Test {
public static void main(String[] args) {
String path = "db.properties";
/* 以文本形式读取配置文件 */
try(BufferedReader br =
new BufferedReader(
new InputStreamReader(
new FileInputStream(path)))) {
String flush;
while ((flush = br.readLine()) != null) {
System.out.println(flush);
}
System.out.println("能够成功地读取文件内容,说明文件路径不存在问题");
} catch (FileNotFoundException e) {
System.err.println("文件不存在!!");
} catch (IOException e) {
System.out.println("IO出现异常");
e.printStackTrace();
}
/* 以配置文件形式读取配置文件 */
Properties pros = new Properties();
try {
pros.load(Thread.currentThread().
getContextClassLoader().getResourceAsStream(path));
} catch (Exception e) {
System.err.println("配置文件连接失败!!");
e.printStackTrace();
}
}
}
pros.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(path));这句代码空指针异常吧
不知道咋回事,求大佬指点