Android 配置文件
来源:互联网 发布:自学英语教材推荐知乎 编辑:程序博客网 时间:2024/05/22 00:16
public class theApp extends Application { Context mContext ; @Override public void onCreate() { super.onCreate(); mContext = getApplicationContext(); Utils.init(mContext); }}
public class Utils { private static Context mContext; public static Properties getNetConfigProperties() { Properties props = new Properties();// InputStream in = Utils.class.getResourceAsStream("/netconfig.properties"); Context c ; InputStream in = null; try { in = mContext.getAssets().open("netconfig.properties"); } catch (IOException e) { e.printStackTrace(); } try { props.load(in); } catch (IOException e) { e.printStackTrace(); } return props; }public static void init(Context context) { mContext = context; }}
使用的地方调用
String str = Utils.getNetConfigProperties().getProperty("name");
改进代码:这样可以将配置文件写在其他可以修改的地方,便于在apk外手动修改(我们项目中暂时
未找到打开.properties格式的工具,暂时是用U盘复制替换)
public static Properties getNetConfigProperties() { Log.d(TAG, "Environment="+ Environment.getExternalStorageDirectory());Properties props = new Properties(); File file = new File(Environment.getExternalStorageDirectory(),"Android/data/bbb.properties"); try { InputStream in = new FileInputStream(file); props.load(in); } catch (Exception e) { e.printStackTrace(); } return props; }
0 0
- Android配置文件
- Android 配置文件
- Android - Android.mk配置文件
- 【Android】配置文件属性说明
- Android 配置文件锁设置
- android 配置文件解析
- android 配置文件解析
- Android 配置文件下载不了
- Android配置文件,所有权限
- android解析配置文件
- Android配置文件,所有权限
- Android配置文件selector
- android 获取配置文件ID
- Android配置文件权限一览表
- Android NDK 配置文件详解
- Android 读取Properties配置文件
- Android配置文件,所有权限
- android 获取配置文件信息
- 程序员证明自己智商的时候到了,一大波智力面试题正在靠近
- Why does my Authorize Attribute not work-
- 迭代器
- cmd命令提示符大全
- C# winform 捕获全局异常
- Android 配置文件
- Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files defi
- 智能家居项目中期结项
- spring的aop实现
- RxJava笔记--01
- java的动态代理机制
- C#中new一个对象的过程说明
- OpenGL基本图元转换为GL_TRIANGLES
- 第4章 View的工作原理