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; } }

文件存放于主程序里
JAVA android 获取assets文件夹中的properties文件 并从中获取数据

文章图片

JAVA android 获取assets文件夹中的properties文件 并从中获取数据

文章图片

 
获取数据
 
String a = properties.getProperty("a");

【JAVA android 获取assets文件夹中的properties文件 并从中获取数据】 

    推荐阅读