Java 读取配置文件 Properties

            String filePath="src/cn/ac/iscas/pebble/ufe/conf/id.properties";

            InputStream in = new BufferedInputStream(new FileInputStream(filePath));

            int i = 0;

            Properties p = new Properties();

            p.load(in);
p.getProperty(key);

还有一个方式如下:

public class ConfigUtils {

    

    private static final ResourceBundle baseBundle = ResourceBundle.getBundle("cn/ac/iscas/pebble/ufe/conf/id");



    public static String getValue(String key) {

        return baseBundle.getString(key).trim();

    }

首先 id所在的大目录必须在classpath下。如下所示:

Navigator下查看.classpath文件:

<?xml version="1.0" encoding="UTF-8"?>

<classpath>

    <classpathentry kind="src" path="src"/>
…………

 

 

你可能感兴趣的:(properties)