java读写属性配置文件
package readproperties; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * java 读取属性文件 * Created by lgq on 2015/6/4. */ public class ReadProperties { protected static Properties properties; public static void loadProp() { properties = new Properties(); try { //方法一载入配置文件 //properties.load(ReadProperties.class.getResourceAsStream("/jdbc.properties")); //方法二载入配置文件 properties.load(new FileInputStream("src/jdbc.properties")); } catch (IOException e) { e.printStackTrace(); } String driverName = properties.getProperty("jdbc.driverClassName"); String url = properties.getProperty("jdbc.url"); String username = properties.getProperty("jdbc.username"); String password = properties.getProperty("jdbc.password"); System.out.println(driverName); System.out.println(url); System.out.println(username); System.out.println(password); } public static void main(String[] args) { ReadProperties.loadProp(); } }