InputStream和Reader
今天使用Eclipse和idea分别用IO流加载配置文件。
Eclipse中项目相对路径中是src,成功找到。但是转到idea后却找不到该配置文件。报错,找不到该配置文件。
下面是项目结构,项目只是普通java项目
代码:
public class Read {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("src/resources/db.properties");
Properties properties = new Properties();
properties.load(fileInputStream );
String key1 = properties.getProperty("key1");
System.out.println(key1);
}
}
错误截图:
尝试后发现要加上项目名后才可以找到
FileInputStream fileInputStream = new FileInputStream("Property/src/resources/db.properties");
但是在Eclipse中不需要加项目名,路径问题真的很头疼。
这两个软件的工程路径有什么区别吗???