public static void main(String[] args) { // TODO Auto-generated method stub Properties properties = new Properties(); String propertiesDir = System.getProperty("user.dir"); String propertiesFilePath = propertiesDir + File.separator + "src" + File.separator + "Person" + File.separator + "properties" + File.separator + "info.properties"; System.out.println(propertiesDir); System.out.println(propertiesFilePath); try { properties.load(new FileInputStream(new File(propertiesFilePath))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(properties.getProperty("key1")); System.out.println(properties.getProperty("key2")); }
运行结果
C:Userscxleclipse-workspaceJAVA C:Userscxleclipse-workspaceJAVAsrcPersonpropertiesinfo.properties 芙蓉 value2