FileInputStream流的文件名要是硬盘中真实存在的文件,而src是虚拟目录,你可以试试类加载器的方式读取。代码如下:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class properTest {
public static void main(String[] args) throws IOException {
InputStream in = properTest.class.getClass().getResourceAsStream("/a.properties");
Properties prop = new Properties();
prop.load(in);
String value = (String) prop.getProperty("daoName");
System.out.println(value);
}
}
关于 properTest.class.getClass().getResourceAsStream()类加载器的知识,你可以百度一下。