ConfigUtil 工具

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mr_jianrong/article/details/79904614
package com.founder.ics.utils;


import android.content.Context;
import android.content.SharedPreferences;


/**
 * 配置文件操作工具类
 * @author GaoJR
 *
 */
public class ConfigUtil {
private static final String CONFIG_FILE = "ICS_CONF";
//读取配置参数
public static String read(Context context,String key,String defValue){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
return sp.getString(key, defValue);
}
public static long read(Context context,String key,long defValue){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
return sp.getLong(key, defValue);
}
public static int read(Context context,String key,int defValue){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
return sp.getInt(key, defValue);
}
public static float read(Context context,String key,float defValue){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
return sp.getFloat(key, defValue);
}
public static boolean read(Context context,String key,boolean defValue){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
return sp.getBoolean(key, defValue);
}
//写入配置参数
public static void write(Context context,String key,String value){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.putString(key, value);
editor.commit();
}
public static void write(Context context,String key,long value){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.putLong(key, value);
editor.commit();
}


public static void write(Context context,String key,int value){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.putInt(key, value);
editor.commit();
}


public static void write(Context context,String key,float value){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.putFloat(key, value);
editor.commit();
}
public static void write(Context context,String key,boolean value){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.putBoolean(key, value);
editor.commit();
}


public static void remove(Context context,String key){
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0);
SharedPreferences.Editor editor=sp.edit();
editor.remove(key);
editor.commit();
}
}

猜你喜欢

转载自blog.csdn.net/mr_jianrong/article/details/79904614