- Java code
Properties prop=new Properties(); try { FileInputStream fs=new FileInputStream("config.properties"); prop.load(fs); System.out.println(prop.getProperty("cls1")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
以上代码出现异常:
java.io.FileNotFoundException: config.properties (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.TestProperties.main(TestProperties.java:15)
------解决方案--------------------
你的类文件和properties文件要放同一个目录下或者在根目录下建个config目录,把配置文件放进去