1. 程式人生 > >JAVA android 獲取assets資料夾中的properties檔案 並從中獲取資料

JAVA android 獲取assets資料夾中的properties檔案 並從中獲取資料

class PropertiesUtils {
    private static Properties properties = null;
    private static void readProperties() {
        try {
            InputStream in = PropertiesUtils.class.getResourceAsStream("/assets/sdk_param_config.properties");
            properties = new Properties();
            properties.load(in
); } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { Log.e("PropertiesUtils", "get nothing"); e.printStackTrace(); } } public static Properties getProperties() { if (properties == null) { readProperties(); } return
properties; } }

檔案存放於主程式裡
這裡寫圖片描述
獲取資料
這裡寫圖片描述

String a = properties.getProperty("a");