{"id":8170,"date":"2024-06-20T13:01:01","date_gmt":"2024-06-20T05:01:01","guid":{"rendered":""},"modified":"2024-06-20T13:01:01","modified_gmt":"2024-06-20T05:01:01","slug":"android app\u5feb\u901f\u5f00\u53d1_android app\u5f00\u53d1\u5de5\u5177","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8170.html","title":{"rendered":"android app\u5feb\u901f\u5f00\u53d1_android app\u5f00\u53d1\u5de5\u5177"},"content":{"rendered":"<div style=\"font-size:16px;\">\n<p>\u4e00\u3001\u65e5\u5fd7\u5de5\u5177\u7c7b Log.java<\/p>\n<p>public class L<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private L()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* \u4e0d\u53ef\u88ab\u5b9e\u4f8b\u5316 *\/<\/p>\n<p>throw new UnsupportedOperationException(\"Cannot be instantiated!\");<\/p>\n<p>}<\/p>\n<p>\/\/ \u662f\u5426\u9700\u8981\u6253\u5370bug\uff0c\u53ef\u4ee5\u5728application\u7684onCreate\u51fd\u6570\u91cc\u9762\u521d\u59cb\u5316<\/p>\n<p>public static boolean isDebug = true;<\/p>\n<p>private static final String TAG = \"DefaultTag\";<\/p>\n<p>\/\/ \u4e0b\u9762\u56db\u4e2a\u662f\u9ed8\u8ba4tag\u7684\u51fd\u6570<\/p>\n<p>public static void i(String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.i(TAG, msg);<\/p>\n<p>}<\/p>\n<p>public static void d(String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.d(TAG, msg);<\/p>\n<p>}<\/p>\n<p>public static void e(String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.e(TAG, msg);<\/p>\n<p>}<\/p>\n<p>public static void v(String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.v(TAG, msg);<\/p>\n<p>}<\/p>\n<p>\/\/ \u4e0b\u9762\u662f\u4f20\u5165\u81ea\u5b9a\u4e49tag\u7684\u51fd\u6570<\/p>\n<p>public static void i(String tag, String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.i(tag, msg);<\/p>\n<p>}<\/p>\n<p>public static void d(String tag, String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.i(tag, msg);<\/p>\n<p>}<\/p>\n<p>public static void e(String tag, String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.i(tag, msg);<\/p>\n<p>}<\/p>\n<p>public static void v(String tag, String msg)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isDebug)<\/p>\n<p>Log.i(tag, msg);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u4e8c\u3001Toast\u7edf\u4e00\u7ba1\u7406\u7c7b Tost.java<\/p>\n<p>public class T<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private T()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>public static boolean isShow = true;<\/p>\n<p>\/**<\/p>\n<p>* \u77ed\u65f6\u95f4\u663e\u793aToast<\/p>\n<p>*\/<\/p>\n<p>public static void showShort(Context context, CharSequence message)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, Toast.LENGTH_SHORT).show();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u77ed\u65f6\u95f4\u663e\u793aToast<\/p>\n<p>* @param message \u8981\u663e\u793a\u7684\u5b57\u7b26\u4e32\u8d44\u6e90\u7684id<\/p>\n<p>*\/<\/p>\n<p>public static void showShort(Context context, int message)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, Toast.LENGTH_SHORT).show();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u957f\u65f6\u95f4\u663e\u793aToast<\/p>\n<p>*\/<\/p>\n<p>public static void showLong(Context context, CharSequence message)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, Toast.LENGTH_LONG).show();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u957f\u65f6\u95f4\u663e\u793aToast<\/p>\n<p>*\/<\/p>\n<p>public static void showLong(Context context, int message)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, Toast.LENGTH_LONG).show();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u81ea\u5b9a\u4e49\u663e\u793aToast\u65f6\u95f4<\/p>\n<p>*\/<\/p>\n<p>public static void show(Context context, CharSequence message, int duration)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, duration).show();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u81ea\u5b9a\u4e49\u663e\u793aToast\u65f6\u95f4<\/p>\n<p>*\/<\/p>\n<p>public static void show(Context context, int message, int duration)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isShow)<\/p>\n<p>Toast.makeText(context, message, duration).show();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u4e09\u3001SharedPreferences\u5c01\u88c5\u7c7b SPUtils.java \u548c PreferencesUtils.java<\/p>\n<p>1. SPUtils.java<\/p>\n<p>public class SPUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/**<\/p>\n<p>* \u4fdd\u5b58\u5728\u624b\u673a\u91cc\u9762\u7684\u6587\u4ef6\u540d<\/p>\n<p>*\/<\/p>\n<p>public static final String FILE_NAME = \"share_data\";<\/p>\n<p>\/**<\/p>\n<p>* \u4fdd\u5b58\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u9700\u8981\u62ff\u5230\u4fdd\u5b58\u6570\u636e\u7684\u5177\u4f53\u7c7b\u578b\uff0c\u7136\u540e\u6839\u636e\u7c7b\u578b\u8c03\u7528\u4e0d\u540c\u7684\u4fdd\u5b58\u65b9\u6cd5<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key<\/p>\n<p>* @param object<\/p>\n<p>*\/<\/p>\n<p>public static void put(Context context, String key, Object object)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = sp.edit();<\/p>\n<p>if (object instanceof String)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putString(key, (String) object);<\/p>\n<p>} else if (object instanceof Integer)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putInt(key, (Integer) object);<\/p>\n<p>} else if (object instanceof Boolean)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putBoolean(key, (Boolean) object);<\/p>\n<p>} else if (object instanceof Float)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putFloat(key, (Float) object);<\/p>\n<p>} else if (object instanceof Long)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putLong(key, (Long) object);<\/p>\n<p>} else<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>editor.putString(key, object.toString());<\/p>\n<p>}<\/p>\n<p>SharedPreferencesCompat.apply(editor);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5f97\u5230\u4fdd\u5b58\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u6839\u636e\u9ed8\u8ba4\u503c\u5f97\u5230\u4fdd\u5b58\u7684\u6570\u636e\u7684\u5177\u4f53\u7c7b\u578b\uff0c\u7136\u540e\u8c03\u7528\u76f8\u5bf9\u4e8e\u7684\u65b9\u6cd5\u83b7\u53d6\u503c<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key<\/p>\n<p>* @param defaultObject<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static Object get(Context context, String key, Object defaultObject)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>if (defaultObject instanceof String)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return sp.getString(key, (String) defaultObject);<\/p>\n<p>} else if (defaultObject instanceof Integer)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return sp.getInt(key, (Integer) defaultObject);<\/p>\n<p>} else if (defaultObject instanceof Boolean)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return sp.getBoolean(key, (Boolean) defaultObject);<\/p>\n<p>} else if (defaultObject instanceof Float)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return sp.getFloat(key, (Float) defaultObject);<\/p>\n<p>} else if (defaultObject instanceof Long)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return sp.getLong(key, (Long) defaultObject);<\/p>\n<p>}<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u79fb\u9664\u67d0\u4e2akey\u503c\u5df2\u7ecf\u5bf9\u5e94\u7684\u503c<\/p>\n<p>* @param context<\/p>\n<p>* @param key<\/p>\n<p>*\/<\/p>\n<p>public static void remove(Context context, String key)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = sp.edit();<\/p>\n<p>editor.remove(key);<\/p>\n<p>SharedPreferencesCompat.apply(editor);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u6e05\u9664\u6240\u6709\u6570\u636e<\/p>\n<p>* @param context<\/p>\n<p>*\/<\/p>\n<p>public static void clear(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = sp.edit();<\/p>\n<p>editor.clear();<\/p>\n<p>SharedPreferencesCompat.apply(editor);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u67e5\u8be2\u67d0\u4e2akey\u662f\u5426\u5df2\u7ecf\u5b58\u5728<\/p>\n<p>* @param context<\/p>\n<p>* @param key<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean contains(Context context, String key)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>return sp.contains(key);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u8fd4\u56de\u6240\u6709\u7684\u952e\u503c\u5bf9<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static Map getAll(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences sp = context.getSharedPreferences(FILE_NAME,<\/p>\n<p>Context.MODE_PRIVATE);<\/p>\n<p>return sp.getAll();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u521b\u5efa\u4e00\u4e2a\u89e3\u51b3SharedPreferencesCompat.apply\u65b9\u6cd5\u7684\u4e00\u4e2a\u517c\u5bb9\u7c7b<\/p>\n<p>*<\/p>\n<p>* @author zhy<\/p>\n<p>*<\/p>\n<p>*\/<\/p>\n<p>private static class SharedPreferencesCompat<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private static final Method sApplyMethod = findApplyMethod();<\/p>\n<p>\/**<\/p>\n<p>* \u53cd\u5c04\u67e5\u627eapply\u7684\u65b9\u6cd5<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>@SuppressWarnings({ \"unchecked\", \"rawtypes\" })<\/p>\n<p>private static Method findApplyMethod()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>Class clz = SharedPreferences.Editor.class;<\/p>\n<p>return clz.getMethod(\"apply\");<\/p>\n<p>} catch (NoSuchMethodException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>}<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5982\u679c\u627e\u5230\u5219\u4f7f\u7528apply\u6267\u884c\uff0c\u5426\u5219\u4f7f\u7528commit<\/p>\n<p>*<\/p>\n<p>* @param editor<\/p>\n<p>*\/<\/p>\n<p>public static void apply(SharedPreferences.Editor editor)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (sApplyMethod != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>sApplyMethod.invoke(editor);<\/p>\n<p>return;<\/p>\n<p>}<\/p>\n<p>} catch (IllegalArgumentException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>} catch (IllegalAccessException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>} catch (InvocationTargetException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>}<\/p>\n<p>editor.commit();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5bf9SharedPreference\u7684\u4f7f\u7528\u505a\u4e86\u5efa\u8bae\u7684\u5c01\u88c5\uff0c\u5bf9\u5916\u516c\u5e03\u51faput\uff0cget\uff0cremove\uff0cclear\u7b49\u7b49\u65b9\u6cd5\uff1b<\/p>\n<p>\u6ce8\u610f\u4e00\u70b9\uff0c\u91cc\u9762\u6240\u6709\u7684commit\u64cd\u4f5c\u4f7f\u7528\u4e86SharedPreferencesCompat.apply\u8fdb\u884c\u4e86\u66ff\u4ee3\uff0c\u76ee\u7684\u662f\u5c3d\u53ef\u80fd\u7684\u4f7f\u7528apply\u4ee3\u66ffcommit.<\/p>\n<p>\u9996\u5148\u8bf4\u4e0b\u4e3a\u4ec0\u4e48\uff0c\u56e0\u4e3acommit\u65b9\u6cd5\u662f\u540c\u6b65\u7684\uff0c\u5e76\u4e14\u6211\u4eec\u5f88\u591a\u65f6\u5019\u7684commit\u64cd\u4f5c\u90fd\u662fUI\u7ebf\u7a0b\u4e2d\uff0c\u6bd5\u7adf\u662fIO\u64cd\u4f5c\uff0c\u5c3d\u53ef\u80fd\u5f02\u6b65\uff1b<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u4f7f\u7528apply\u8fdb\u884c\u66ff\u4ee3\uff0capply\u5f02\u6b65\u7684\u8fdb\u884c\u5199\u5165\uff1b<\/p>\n<p>\u4f46\u662fapply\u76f8\u5f53\u4e8ecommit\u6765\u8bf4\u662fnew API\u5462\uff0c\u4e3a\u4e86\u66f4\u597d\u7684\u517c\u5bb9\uff0c\u6211\u4eec\u505a\u4e86\u9002\u914d\uff1b<\/p>\n<p>SharedPreferencesCompat\u4e5f\u53ef\u4ee5\u7ed9\u5927\u5bb6\u521b\u5efa\u517c\u5bb9\u7c7b\u63d0\u4f9b\u4e86\u4e00\u5b9a\u7684\u53c2\u8003<\/p>\n<p>2. SPUtils.java<\/p>\n<p>public class PreferencesUtils {<br \/>\n  <!-- --><\/p>\n<p>public static String PREFERENCE_NAME = \"TrineaAndroidCommon\";<\/p>\n<p>private PreferencesUtils() {<br \/>\n  <!-- --><\/p>\n<p>throw new AssertionError();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* put string preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to modify<\/p>\n<p>* @param value The new value for the preference<\/p>\n<p>* @return True if the new values were successfully written to persistent storage.<\/p>\n<p>*\/<\/p>\n<p>public static boolean putString(Context context, String key, String value) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = settings.edit();<\/p>\n<p>editor.putString(key, value);<\/p>\n<p>return editor.commit();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get string preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @return The preference value if it exists, or null. Throws ClassCastException if there is a preference with this<\/p>\n<p>* name that is not a string<\/p>\n<p>* @see #getString(Context, String, String)<\/p>\n<p>*\/<\/p>\n<p>public static String getString(Context context, String key) {<br \/>\n  <!-- --><\/p>\n<p>return getString(context, key, null);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get string preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @param defaultValue Value to return if this preference does not exist<\/p>\n<p>* @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with<\/p>\n<p>* this name that is not a string<\/p>\n<p>*\/<\/p>\n<p>public static String getString(Context context, String key, String defaultValue) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>return settings.getString(key, defaultValue);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* put int preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to modify<\/p>\n<p>* @param value The new value for the preference<\/p>\n<p>* @return True if the new values were successfully written to persistent storage.<\/p>\n<p>*\/<\/p>\n<p>public static boolean putInt(Context context, String key, int value) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = settings.edit();<\/p>\n<p>editor.putInt(key, value);<\/p>\n<p>return editor.commit();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get int preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @return The preference value if it exists, or -. Throws ClassCastException if there is a preference with this<\/p>\n<p>* name that is not a int<\/p>\n<p>* @see #getInt(Context, String, int)<\/p>\n<p>*\/<\/p>\n<p>public static int getInt(Context context, String key) {<br \/>\n  <!-- --><\/p>\n<p>return getInt(context, key, -);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get int preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @param defaultValue Value to return if this preference does not exist<\/p>\n<p>* @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with<\/p>\n<p>* this name that is not a int<\/p>\n<p>*\/<\/p>\n<p>public static int getInt(Context context, String key, int defaultValue) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>return settings.getInt(key, defaultValue);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* put long preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to modify<\/p>\n<p>* @param value The new value for the preference<\/p>\n<p>* @return True if the new values were successfully written to persistent storage.<\/p>\n<p>*\/<\/p>\n<p>public static boolean putLong(Context context, String key, long value) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = settings.edit();<\/p>\n<p>editor.putLong(key, value);<\/p>\n<p>return editor.commit();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get long preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @return The preference value if it exists, or -. Throws ClassCastException if there is a preference with this<\/p>\n<p>* name that is not a long<\/p>\n<p>* @see #getLong(Context, String, long)<\/p>\n<p>*\/<\/p>\n<p>public static long getLong(Context context, String key) {<br \/>\n  <!-- --><\/p>\n<p>return getLong(context, key, -);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get long preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @param defaultValue Value to return if this preference does not exist<\/p>\n<p>* @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with<\/p>\n<p>* this name that is not a long<\/p>\n<p>*\/<\/p>\n<p>public static long getLong(Context context, String key, long defaultValue) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>return settings.getLong(key, defaultValue);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* put float preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to modify<\/p>\n<p>* @param value The new value for the preference<\/p>\n<p>* @return True if the new values were successfully written to persistent storage.<\/p>\n<p>*\/<\/p>\n<p>public static boolean putFloat(Context context, String key, float value) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = settings.edit();<\/p>\n<p>editor.putFloat(key, value);<\/p>\n<p>return editor.commit();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get float preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @return The preference value if it exists, or -. Throws ClassCastException if there is a preference with this<\/p>\n<p>* name that is not a float<\/p>\n<p>* @see #getFloat(Context, String, float)<\/p>\n<p>*\/<\/p>\n<p>public static float getFloat(Context context, String key) {<br \/>\n  <!-- --><\/p>\n<p>return getFloat(context, key, -);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get float preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @param defaultValue Value to return if this preference does not exist<\/p>\n<p>* @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with<\/p>\n<p>* this name that is not a float<\/p>\n<p>*\/<\/p>\n<p>public static float getFloat(Context context, String key, float defaultValue) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>return settings.getFloat(key, defaultValue);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* put boolean preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to modify<\/p>\n<p>* @param value The new value for the preference<\/p>\n<p>* @return True if the new values were successfully written to persistent storage.<\/p>\n<p>*\/<\/p>\n<p>public static boolean putBoolean(Context context, String key, boolean value) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = settings.edit();<\/p>\n<p>editor.putBoolean(key, value);<\/p>\n<p>return editor.commit();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get boolean preferences, default is false<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @return The preference value if it exists, or false. Throws ClassCastException if there is a preference with this<\/p>\n<p>* name that is not a boolean<\/p>\n<p>* @see #getBoolean(Context, String, boolean)<\/p>\n<p>*\/<\/p>\n<p>public static boolean getBoolean(Context context, String key) {<br \/>\n  <!-- --><\/p>\n<p>return getBoolean(context, key, false);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get boolean preferences<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param key The name of the preference to retrieve<\/p>\n<p>* @param defaultValue Value to return if this preference does not exist<\/p>\n<p>* @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with<\/p>\n<p>* this name that is not a boolean<\/p>\n<p>*\/<\/p>\n<p>public static boolean getBoolean(Context context, String key, boolean defaultValue) {<br \/>\n  <!-- --><\/p>\n<p>SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);<\/p>\n<p>return settings.getBoolean(key, defaultValue);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u56db\u3001\u5355\u4f4d\u8f6c\u6362\u7c7b DensityUtils.java<\/p>\n<p>public class DensityUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private DensityUtils()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* dp\u8f6cpx<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param val<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static int dppx(Context context, float dpVal)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,<\/p>\n<p>dpVal, context.getResources().getDisplayMetrics());<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* sp\u8f6cpx<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param val<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static int sppx(Context context, float spVal)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,<\/p>\n<p>spVal, context.getResources().getDisplayMetrics());<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* px\u8f6cdp<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param pxVal<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static float pxdp(Context context, float pxVal)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>final float scale = context.getResources().getDisplayMetrics().density;<\/p>\n<p>return (pxVal \/ scale);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* px\u8f6csp<\/p>\n<p>*<\/p>\n<p>* @param fontScale<\/p>\n<p>* @param pxVal<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static float pxsp(Context context, float pxVal)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return (pxVal \/ context.getResources().getDisplayMetrics().scaledDensity);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>TypedValue\uff1a<\/p>\n<p>Container for a dynamically typed data value. Primarily used with Resources for holding resource values.<\/p>\n<p>applyDimension(int unit, float value, DisplayMetrics metrics)\uff1a<\/p>\n<p>Converts an unpacked complex data value holding a dimension to its final floating point value.<\/p>\n<p>\u4e94\u3001SD\u5361\u76f8\u5173\u8f85\u52a9\u7c7b SDCardUtils.java<\/p>\n<p>public class SDCardUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private SDCardUtils()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5224\u65adSDCard\u662f\u5426\u53ef\u7528<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean isSDCardEnable()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return Environment.getExternalStorageState().equals(<\/p>\n<p>Environment.MEDIA_MOUNTED);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6SD\u5361\u8def\u5f84<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getSDCardPath()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return Environment.getExternalStorageDirectory().getAbsolutePath()<\/p>\n<p>+ File.separator;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6SD\u5361\u7684\u5269\u4f59\u5bb9\u91cf \u5355\u4f4dbyte<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static long getSDCardAllSize()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (isSDCardEnable())<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>StatFs stat = new StatFs(getSDCardPath());<\/p>\n<p>\/\/ \u83b7\u53d6\u7a7a\u95f2\u7684\u6570\u636e\u5757\u7684\u6570\u91cf<\/p>\n<p>long availableBlocks = (long) stat.getAvailableBlocks() - ;<\/p>\n<p>\/\/ \u83b7\u53d6\u5355\u4e2a\u6570\u636e\u5757\u7684\u5927\u5c0f(byte)<\/p>\n<p>long freeBlocks = stat.getAvailableBlocks();<\/p>\n<p>return freeBlocks * availableBlocks;<\/p>\n<p>}<\/p>\n<p>return ;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6\u6307\u5b9a\u8def\u5f84\u6240\u5728\u7a7a\u95f4\u7684\u5269\u4f59\u53ef\u7528\u5bb9\u91cf\u5b57\u8282\u6570\uff0c\u5355\u4f4dbyte<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return \u5bb9\u91cf\u5b57\u8282 SDCard\u53ef\u7528\u7a7a\u95f4\uff0c\u5185\u90e8\u5b58\u50a8\u53ef\u7528\u7a7a\u95f4<\/p>\n<p>*\/<\/p>\n<p>public static long getFreeBytes(String filePath)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/\/ \u5982\u679c\u662fsd\u5361\u7684\u4e0b\u7684\u8def\u5f84\uff0c\u5219\u83b7\u53d6sd\u5361\u53ef\u7528\u5bb9\u91cf<\/p>\n<p>if (filePath.startsWith(getSDCardPath()))<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>filePath = getSDCardPath();<\/p>\n<p>} else<\/p>\n<p>{\/\/ \u5982\u679c\u662f\u5185\u90e8\u5b58\u50a8\u7684\u8def\u5f84\uff0c\u5219\u83b7\u53d6\u5185\u5b58\u5b58\u50a8\u7684\u53ef\u7528\u5bb9\u91cf<\/p>\n<p>filePath = Environment.getDataDirectory().getAbsolutePath();<\/p>\n<p>}<\/p>\n<p>StatFs stat = new StatFs(filePath);<\/p>\n<p>long availableBlocks = (long) stat.getAvailableBlocks() - ;<\/p>\n<p>return stat.getBlockSize() * availableBlocks;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6\u7cfb\u7edf\u5b58\u50a8\u8def\u5f84<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getRootDirectoryPath()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return Environment.getRootDirectory().getAbsolutePath();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>StatFs \u662fAndroid\u63d0\u4f9b\u7684\u4e00\u4e2a\u7c7b\uff1a<\/p>\n<p>Retrieve overall information about the space on a filesystem. This is a wrapper for Unix statvfs().<\/p>\n<p>\u68c0\u7d22\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u6574\u4f53\u4fe1\u606f\u7a7a\u95f4\u3002\u8fd9\u662f\u4e00\u4e2aUnix statvfs() \u5305\u88c5\u5668<\/p>\n<p>\u516d\u3001\u5c4f\u5e55\u76f8\u5173\u8f85\u52a9\u7c7b ScreenUtils.java<\/p>\n<p>public class ScreenUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private ScreenUtils()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u5f97\u5c4f\u5e55\u9ad8\u5ea6<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static int getScreenWidth(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>WindowManager wm = (WindowManager) context<\/p>\n<p>.getSystemService(Context.WINDOW_SERVICE);<\/p>\n<p>DisplayMetrics outMetrics = new DisplayMetrics();<\/p>\n<p>wm.getDefaultDisplay().getMetrics(outMetrics);<\/p>\n<p>return outMetrics.widthPixels;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u5f97\u5c4f\u5e55\u5bbd\u5ea6<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static int getScreenHeight(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>WindowManager wm = (WindowManager) context<\/p>\n<p>.getSystemService(Context.WINDOW_SERVICE);<\/p>\n<p>DisplayMetrics outMetrics = new DisplayMetrics();<\/p>\n<p>wm.getDefaultDisplay().getMetrics(outMetrics);<\/p>\n<p>return outMetrics.heightPixels;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u5f97\u72b6\u6001\u680f\u7684\u9ad8\u5ea6<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static int getStatusHeight(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>int statusHeight = -;<\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>Class&gt; clazz = Class.forName(\"com.android.internal.R$dimen\");<\/p>\n<p>Object object = clazz.newInstance();<\/p>\n<p>int height = Integer.parseInt(clazz.getField(\"status_bar_height\")<\/p>\n<p>.get(object).toString());<\/p>\n<p>statusHeight = context.getResources().getDimensionPixelSize(height);<\/p>\n<p>} catch (Exception e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>return statusHeight;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6\u5f53\u524d\u5c4f\u5e55\u622a\u56fe\uff0c\u5305\u542b\u72b6\u6001\u680f<\/p>\n<p>*<\/p>\n<p>* @param activity<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static Bitmap snapShotWithStatusBar(Activity activity)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>View view = activity.getWindow().getDecorView();<\/p>\n<p>view.setDrawingCacheEnabled(true);<\/p>\n<p>view.buildDrawingCache();<\/p>\n<p>Bitmap bmp = view.getDrawingCache();<\/p>\n<p>int width = getScreenWidth(activity);<\/p>\n<p>int height = getScreenHeight(activity);<\/p>\n<p>Bitmap bp = null;<\/p>\n<p>bp = Bitmap.createBitmap(bmp, , , width, height);<\/p>\n<p>view.destroyDrawingCache();<\/p>\n<p>return bp;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6\u5f53\u524d\u5c4f\u5e55\u622a\u56fe\uff0c\u4e0d\u5305\u542b\u72b6\u6001\u680f<\/p>\n<p>*<\/p>\n<p>* @param activity<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static Bitmap snapShotWithoutStatusBar(Activity activity)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>View view = activity.getWindow().getDecorView();<\/p>\n<p>view.setDrawingCacheEnabled(true);<\/p>\n<p>view.buildDrawingCache();<\/p>\n<p>Bitmap bmp = view.getDrawingCache();<\/p>\n<p>Rect frame = new Rect();<\/p>\n<p>activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);<\/p>\n<p>int statusBarHeight = frame.top;<\/p>\n<p>int width = getScreenWidth(activity);<\/p>\n<p>int height = getScreenHeight(activity);<\/p>\n<p>Bitmap bp = null;<\/p>\n<p>bp = Bitmap.createBitmap(bmp, , statusBarHeight, width, height<\/p>\n<p>- statusBarHeight);<\/p>\n<p>view.destroyDrawingCache();<\/p>\n<p>return bp;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u4e03\u3001App\u76f8\u5173\u8f85\u52a9\u7c7b APPUtils.java<\/p>\n<p>public class AppUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private AppUtils()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0<\/p>\n<p>*\/<\/p>\n<p>public static String getAppName(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>PackageManager packageManager = context.getPackageManager();<\/p>\n<p>PackageInfo packageInfo = packageManager.getPackageInfo(<\/p>\n<p>context.getPackageName(), );<\/p>\n<p>int labelRes = packageInfo.applicationInfo.labelRes;<\/p>\n<p>return context.getResources().getString(labelRes);<\/p>\n<p>} catch (NameNotFoundException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* [\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u7248\u672c\u540d\u79f0\u4fe1\u606f]<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @return \u5f53\u524d\u5e94\u7528\u7684\u7248\u672c\u540d\u79f0<\/p>\n<p>*\/<\/p>\n<p>public static String getVersionName(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>PackageManager packageManager = context.getPackageManager();<\/p>\n<p>PackageInfo packageInfo = packageManager.getPackageInfo(<\/p>\n<p>context.getPackageName(), );<\/p>\n<p>return packageInfo.versionName;<\/p>\n<p>} catch (NameNotFoundException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u516b\u3001\u8f6f\u952e\u76d8\u76f8\u5173\u8f85\u52a9\u7c7bKeyBoardUtils.java<\/p>\n<p>\/**<\/p>\n<p>* \u6253\u5f00\u6216\u5173\u95ed\u8f6f\u952e\u76d8<\/p>\n<p>*\/<\/p>\n<p>public class KeyBoardUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/**<\/p>\n<p>* \u6253\u5361\u8f6f\u952e\u76d8<\/p>\n<p>*<\/p>\n<p>* @param mEditText \u8f93\u5165\u6846<\/p>\n<p>* @param mContext \u4e0a\u4e0b\u6587<\/p>\n<p>*\/<\/p>\n<p>public static void openKeybord(EditText mEditText, Context mContext)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>InputMethodManager imm = (InputMethodManager) mContext<\/p>\n<p>.getSystemService(Context.INPUT_METHOD_SERVICE);<\/p>\n<p>imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);<\/p>\n<p>imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,<\/p>\n<p>InputMethodManager.HIDE_IMPLICIT_ONLY);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5173\u95ed\u8f6f\u952e\u76d8<\/p>\n<p>*<\/p>\n<p>* @param mEditText \u8f93\u5165\u6846<\/p>\n<p>* @param mContext \u4e0a\u4e0b\u6587<\/p>\n<p>*\/<\/p>\n<p>public static void closeKeybord(EditText mEditText, Context mContext)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>InputMethodManager imm = (InputMethodManager) mContext<\/p>\n<p>.getSystemService(Context.INPUT_METHOD_SERVICE);<\/p>\n<p>imm.hideSoftInputFromWindow(mEditText.getWindowToken(), );<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u4e5d\u3001\u7f51\u7edc\u76f8\u5173\u8f85\u52a9\u7c7b NetUtils.java<\/p>\n<p>public class NetUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private NetUtils()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/* cannot be instantiated *\/<\/p>\n<p>throw new UnsupportedOperationException(\"cannot be instantiated\");<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5224\u65ad\u7f51\u7edc\u662f\u5426\u8fde\u63a5<\/p>\n<p>*\/<\/p>\n<p>public static boolean isConnected(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>ConnectivityManager connectivity = (ConnectivityManager) context<\/p>\n<p>.getSystemService(Context.CONNECTIVITY_SERVICE);<\/p>\n<p>if (null != connectivity)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>NetworkInfo info = connectivity.getActiveNetworkInfo();<\/p>\n<p>if (null != info &amp;&amp; info.isConnected())<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (info.getState() == NetworkInfo.State.CONNECTED)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5224\u65ad\u662f\u5426\u662fwifi\u8fde\u63a5<\/p>\n<p>*\/<\/p>\n<p>public static boolean isWifi(Context context)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>ConnectivityManager cm = (ConnectivityManager) context<\/p>\n<p>.getSystemService(Context.CONNECTIVITY_SERVICE);<\/p>\n<p>if (cm == null)<\/p>\n<p>return false;<\/p>\n<p>return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u6253\u5f00\u7f51\u7edc\u8bbe\u7f6e\u754c\u9762<\/p>\n<p>*\/<\/p>\n<p>public static void openSetting(Activity activity)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>Intent intent = new Intent(\"\/\");<\/p>\n<p>ComponentName cm = new ComponentName(\"com.android.settings\",<\/p>\n<p>\"com.android.settings.WirelessSettings\");<\/p>\n<p>intent.setComponent(cm);<\/p>\n<p>intent.setAction(\"android.intent.action.VIEW\");<\/p>\n<p>activity.startActivityForResult(intent, );<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u3001Http\u76f8\u5173\u8f85\u52a9\u7c7b HttpUtils.java<\/p>\n<p>\/**<\/p>\n<p>* Http\u8bf7\u6c42\u7684\u5de5\u5177\u7c7b<\/p>\n<p>*\/<\/p>\n<p>public class HttpUtils<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>private static final int TIMEOUT_IN_MILLIONS = ;<\/p>\n<p>public interface CallBack<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>void onRequestComplete(String result);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5f02\u6b65\u7684Get\u8bf7\u6c42<\/p>\n<p>*<\/p>\n<p>* @param urlStr<\/p>\n<p>* @param callBack<\/p>\n<p>*\/<\/p>\n<p>public static void doGetAsyn(final String urlStr, final CallBack callBack)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>new Thread()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>public void run()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>String result = doGet(urlStr);<\/p>\n<p>if (callBack != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>callBack.onRequestComplete(result);<\/p>\n<p>}<\/p>\n<p>} catch (Exception e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>};<\/p>\n<p>}.start();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5f02\u6b65\u7684Post\u8bf7\u6c42<\/p>\n<p>* @param urlStr<\/p>\n<p>* @param params<\/p>\n<p>* @param callBack<\/p>\n<p>* @throws Exception<\/p>\n<p>*\/<\/p>\n<p>public static void doPostAsyn(final String urlStr, final String params,<\/p>\n<p>final CallBack callBack) throws Exception<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>new Thread()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>public void run()<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>String result = doPost(urlStr, params);<\/p>\n<p>if (callBack != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>callBack.onRequestComplete(result);<\/p>\n<p>}<\/p>\n<p>} catch (Exception e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>};<\/p>\n<p>}.start();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* Get\u8bf7\u6c42\uff0c\u83b7\u5f97\u8fd4\u56de\u6570\u636e<\/p>\n<p>*<\/p>\n<p>* @param urlStr<\/p>\n<p>* @return<\/p>\n<p>* @throws Exception<\/p>\n<p>*\/<\/p>\n<p>public static String doGet(String urlStr)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>URL url = null;<\/p>\n<p>HttpURLConnection conn = null;<\/p>\n<p>InputStream is = null;<\/p>\n<p>ByteArrayOutputStream baos = null;<\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>url = new URL(urlStr);<\/p>\n<p>conn = (HttpURLConnection) url.openConnection();<\/p>\n<p>conn.setReadTimeout(TIMEOUT_IN_MILLIONS);<\/p>\n<p>conn.setConnectTimeout(TIMEOUT_IN_MILLIONS);<\/p>\n<p>conn.setRequestMethod(\"GET\");<\/p>\n<p>conn.setRequestProperty(\"accept\", \"*\/*\");<\/p>\n<p>conn.setRequestProperty(\"connection\", \"Keep-Alive\");<\/p>\n<p>if (conn.getResponseCode() == )<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>is = conn.getInputStream();<\/p>\n<p>baos = new ByteArrayOutputStream();<\/p>\n<p>int len = -;<\/p>\n<p>byte[] buf = new byte[];<\/p>\n<p>while ((len = is.read(buf)) != -)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>baos.write(buf, , len);<\/p>\n<p>}<\/p>\n<p>baos.flush();<\/p>\n<p>return baos.toString();<\/p>\n<p>} else<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\" responseCode is not ... \");<\/p>\n<p>}<\/p>\n<p>} catch (Exception e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>} finally<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (is != null)<\/p>\n<p>is.close();<\/p>\n<p>} catch (IOException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>}<\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (baos != null)<\/p>\n<p>baos.close();<\/p>\n<p>} catch (IOException e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>}<\/p>\n<p>conn.disconnect();<\/p>\n<p>}<\/p>\n<p>return null ;<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* \u5411\u6307\u5b9a URL \u53d1\u9001POST\u65b9\u6cd5\u7684\u8bf7\u6c42<\/p>\n<p>*<\/p>\n<p>* @param url<\/p>\n<p>* \u53d1\u9001\u8bf7\u6c42\u7684 URL<\/p>\n<p>* @param param<\/p>\n<p>* \u8bf7\u6c42\u53c2\u6570\uff0c\u8bf7\u6c42\u53c2\u6570\u5e94\u8be5\u662f name=value&amp;name=value \u7684\u5f62\u5f0f\u3002<\/p>\n<p>* @return \u6240\u4ee3\u8868\u8fdc\u7a0b\u8d44\u6e90\u7684\u54cd\u5e94\u7ed3\u679c<\/p>\n<p>* @throws Exception<\/p>\n<p>*\/<\/p>\n<p>public static String doPost(String url, String param)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>PrintWriter out = null;<\/p>\n<p>BufferedReader in = null;<\/p>\n<p>String result = \"\";<\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>URL realUrl = new URL(url);<\/p>\n<p>\/\/ \u6253\u5f00\u548cURL\u4e4b\u95f4\u7684\u8fde\u63a5<\/p>\n<p>HttpURLConnection conn = (HttpURLConnection) realUrl<\/p>\n<p>.openConnection();<\/p>\n<p>\/\/ \u8bbe\u7f6e\u901a\u7528\u7684\u8bf7\u6c42\u5c5e\u6027<\/p>\n<p>conn.setRequestProperty(\"accept\", \"*\/*\");<\/p>\n<p>conn.setRequestProperty(\"connection\", \"Keep-Alive\");<\/p>\n<p>conn.setRequestMethod(\"POST\");<\/p>\n<p>conn.setRequestProperty(\"Content-Type\",<\/p>\n<p>\"application\/x-www-form-urlencoded\");<\/p>\n<p>conn.setRequestProperty(\"charset\", \"utf-\");<\/p>\n<p>conn.setUseCaches(false);<\/p>\n<p>\/\/ \u53d1\u9001POST\u8bf7\u6c42\u5fc5\u987b\u8bbe\u7f6e\u5982\u4e0b\u4e24\u884c<\/p>\n<p>conn.setDoOutput(true);<\/p>\n<p>conn.setDoInput(true);<\/p>\n<p>conn.setReadTimeout(TIMEOUT_IN_MILLIONS);<\/p>\n<p>conn.setConnectTimeout(TIMEOUT_IN_MILLIONS);<\/p>\n<p>if (param != null &amp;&amp; !param.trim().equals(\"\"))<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>\/\/ \u83b7\u53d6URLConnection\u5bf9\u8c61\u5bf9\u5e94\u7684\u8f93\u51fa\u6d41<\/p>\n<p>out = new PrintWriter(conn.getOutputStream());<\/p>\n<p>\/\/ \u53d1\u9001\u8bf7\u6c42\u53c2\u6570<\/p>\n<p>out.print(param);<\/p>\n<p>\/\/ flush\u8f93\u51fa\u6d41\u7684\u7f13\u51b2<\/p>\n<p>out.flush();<\/p>\n<p>}<\/p>\n<p>\/\/ \u5b9a\u4e49BufferedReader\u8f93\u5165\u6d41\u6765\u8bfb\u53d6URL\u7684\u54cd\u5e94<\/p>\n<p>in = new BufferedReader(<\/p>\n<p>new InputStreamReader(conn.getInputStream()));<\/p>\n<p>String line;<\/p>\n<p>while ((line = in.readLine()) != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>result += line;<\/p>\n<p>}<\/p>\n<p>} catch (Exception e)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>}<\/p>\n<p>\/\/ \u4f7f\u7528finally\u5757\u6765\u5173\u95ed\u8f93\u51fa\u6d41\u3001\u8f93\u5165\u6d41<\/p>\n<p>finally<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>try<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>if (out != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>out.close();<\/p>\n<p>}<\/p>\n<p>if (in != null)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>in.close();<\/p>\n<p>}<\/p>\n<p>} catch (IOException ex)<\/p>\n<p>{<br \/>\n  <!-- --><\/p>\n<p>ex.printStackTrace();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>return result;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u4e00\u3001\u65f6\u95f4\u5de5\u5177\u7c7b TimeUtils.java<\/p>\n<p>public class TimeUtils {<br \/>\n  <!-- --><\/p>\n<p>public static final SimpleDateFormat DEFAULT_DATE_FORMAT =<\/p>\n<p>new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");<\/p>\n<p>public static final SimpleDateFormat DATE_FORMAT_DATE =<\/p>\n<p>new SimpleDateFormat(\"yyyy-MM-dd\");<\/p>\n<p>private TimeUtils() {<br \/>\n  <!-- --><\/p>\n<p>throw new AssertionError();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* long time to string<\/p>\n<p>*<\/p>\n<p>* @param timeInMillis<\/p>\n<p>* @param dateFormat<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {<br \/>\n  <!-- --><\/p>\n<p>return dateFormat.format(new Date(timeInMillis));<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* long time to string, format is {@link #DEFAULT_DATE_FORMAT}<\/p>\n<p>*<\/p>\n<p>* @param timeInMillis<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getTime(long timeInMillis) {<br \/>\n  <!-- --><\/p>\n<p>return getTime(timeInMillis, DEFAULT_DATE_FORMAT);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get current time in milliseconds<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static long getCurrentTimeInLong() {<br \/>\n  <!-- --><\/p>\n<p>return System.currentTimeMillis();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getCurrentTimeInString() {<br \/>\n  <!-- --><\/p>\n<p>return getTime(getCurrentTimeInLong());<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get current time in milliseconds<\/p>\n<p>*<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {<br \/>\n  <!-- --><\/p>\n<p>return getTime(getCurrentTimeInLong(), dateFormat);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u4e8c\u3001\u6587\u4ef6\u5de5\u5177\u7c7b FileUtils.java<\/p>\n<p>public class FileUtils {<br \/>\n  <!-- --><\/p>\n<p>public final static String FILE_EXTENSION_SEPARATOR = \".\";<\/p>\n<p>private FileUtils() {<br \/>\n  <!-- --><\/p>\n<p>throw new AssertionError();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* read file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param charsetName The name of a supported {@link java.nio.charset.Charset charset<code>}<\/code><\/p>\n<p>* @return if file not exist, return null, else return content of file<\/p>\n<p>* @throws RuntimeException if an error occurs while operator BufferedReader<\/p>\n<p>*\/<\/p>\n<p>public static StringBuilder readFile(String filePath, String charsetName) {<br \/>\n  <!-- --><\/p>\n<p>File file = new File(filePath);<\/p>\n<p>StringBuilder fileContent = new StringBuilder(\"\");<\/p>\n<p>if (file == null || !file.isFile()) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>BufferedReader reader = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);<\/p>\n<p>reader = new BufferedReader(is);<\/p>\n<p>String line = null;<\/p>\n<p>while ((line = reader.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>if (!fileContent.toString().equals(\"\")) {<br \/>\n  <!-- --><\/p>\n<p>fileContent.append(\"\\r\\n\");<\/p>\n<p>}<\/p>\n<p>fileContent.append(line);<\/p>\n<p>}<\/p>\n<p>return fileContent;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"IOException occurred. \", e);<\/p>\n<p>} finally {<br \/>\n  <!-- --><\/p>\n<p>IOUtils.close(reader);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param content<\/p>\n<p>* @param append is append, if true, write to the end of file, else clear content of file and write into it<\/p>\n<p>* @return return false if content is empty, true otherwise<\/p>\n<p>* @throws RuntimeException if an error occurs while operator FileWriter<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, String content, boolean append) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isEmpty(content)) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>FileWriter fileWriter = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>makeDirs(filePath);<\/p>\n<p>fileWriter = new FileWriter(filePath, append);<\/p>\n<p>fileWriter.write(content);<\/p>\n<p>return true;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"IOException occurred. \", e);<\/p>\n<p>} finally {<br \/>\n  <!-- --><\/p>\n<p>IOUtils.close(fileWriter);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param contentList<\/p>\n<p>* @param append is append, if true, write to the end of file, else clear content of file and write into it<\/p>\n<p>* @return return false if contentList is empty, true otherwise<\/p>\n<p>* @throws RuntimeException if an error occurs while operator FileWriter<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, List contentList, boolean append) {<br \/>\n  <!-- --><\/p>\n<p>if (ListUtils.isEmpty(contentList)) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>FileWriter fileWriter = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>makeDirs(filePath);<\/p>\n<p>fileWriter = new FileWriter(filePath, append);<\/p>\n<p>int i = ;<\/p>\n<p>for (String line : contentList) {<br \/>\n  <!-- --><\/p>\n<p>if (i++ &gt; ) {<br \/>\n  <!-- --><\/p>\n<p>fileWriter.write(\"\\r\\n\");<\/p>\n<p>}<\/p>\n<p>fileWriter.write(line);<\/p>\n<p>}<\/p>\n<p>return true;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"IOException occurred. \", e);<\/p>\n<p>} finally {<br \/>\n  <!-- --><\/p>\n<p>IOUtils.close(fileWriter);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file, the string will be written to the begin of the file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param content<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, String content) {<br \/>\n  <!-- --><\/p>\n<p>return writeFile(filePath, content, false);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file, the string list will be written to the begin of the file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param contentList<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, List contentList) {<br \/>\n  <!-- --><\/p>\n<p>return writeFile(filePath, contentList, false);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file, the bytes will be written to the begin of the file<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param stream<\/p>\n<p>* @return<\/p>\n<p>* @see {@link #writeFile(String, InputStream, boolean)}<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, InputStream stream) {<br \/>\n  <!-- --><\/p>\n<p>return writeFile(filePath, stream, false);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file<\/p>\n<p>*<\/p>\n<p>* @param file the file to be opened for writing.<\/p>\n<p>* @param stream the input stream<\/p>\n<p>* @param append if <code>true<\/code>, then bytes will be written to the end of the file rather than the beginning<\/p>\n<p>* @return return true<\/p>\n<p>* @throws RuntimeException if an error occurs while operator FileOutputStream<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(String filePath, InputStream stream, boolean append) {<br \/>\n  <!-- --><\/p>\n<p>return writeFile(filePath != null ? new File(filePath) : null, stream, append);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file, the bytes will be written to the begin of the file<\/p>\n<p>*<\/p>\n<p>* @param file<\/p>\n<p>* @param stream<\/p>\n<p>* @return<\/p>\n<p>* @see {@link #writeFile(File, InputStream, boolean)}<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(File file, InputStream stream) {<br \/>\n  <!-- --><\/p>\n<p>return writeFile(file, stream, false);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* write file<\/p>\n<p>*<\/p>\n<p>* @param file the file to be opened for writing.<\/p>\n<p>* @param stream the input stream<\/p>\n<p>* @param append if <code>true<\/code>, then bytes will be written to the end of the file rather than the beginning<\/p>\n<p>* @return return true<\/p>\n<p>* @throws RuntimeException if an error occurs while operator FileOutputStream<\/p>\n<p>*\/<\/p>\n<p>public static boolean writeFile(File file, InputStream stream, boolean append) {<br \/>\n  <!-- --><\/p>\n<p>OutputStream o = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>makeDirs(file.getAbsolutePath());<\/p>\n<p>o = new FileOutputStream(file, append);<\/p>\n<p>byte data[] = new byte[];<\/p>\n<p>int length = -;<\/p>\n<p>while ((length = stream.read(data)) != -) {<br \/>\n  <!-- --><\/p>\n<p>o.write(data, , length);<\/p>\n<p>}<\/p>\n<p>o.flush();<\/p>\n<p>return true;<\/p>\n<p>} catch (FileNotFoundException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"FileNotFoundException occurred. \", e);<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"IOException occurred. \", e);<\/p>\n<p>} finally {<br \/>\n  <!-- --><\/p>\n<p>IOUtils.close(o);<\/p>\n<p>IOUtils.close(stream);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* move file<\/p>\n<p>*<\/p>\n<p>* @param sourceFilePath<\/p>\n<p>* @param destFilePath<\/p>\n<p>*\/<\/p>\n<p>public static void moveFile(String sourceFilePath, String destFilePath) {<br \/>\n  <!-- --><\/p>\n<p>if (TextUtils.isEmpty(sourceFilePath) || TextUtils.isEmpty(destFilePath)) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"Both sourceFilePath and destFilePath cannot be null.\");<\/p>\n<p>}<\/p>\n<p>moveFile(new File(sourceFilePath), new File(destFilePath));<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* move file<\/p>\n<p>*<\/p>\n<p>* @param srcFile<\/p>\n<p>* @param destFile<\/p>\n<p>*\/<\/p>\n<p>public static void moveFile(File srcFile, File destFile) {<br \/>\n  <!-- --><\/p>\n<p>boolean rename = srcFile.renameTo(destFile);<\/p>\n<p>if (!rename) {<br \/>\n  <!-- --><\/p>\n<p>copyFile(srcFile.getAbsolutePath(), destFile.getAbsolutePath());<\/p>\n<p>deleteFile(srcFile.getAbsolutePath());<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* copy file<\/p>\n<p>*<\/p>\n<p>* @param sourceFilePath<\/p>\n<p>* @param destFilePath<\/p>\n<p>* @return<\/p>\n<p>* @throws RuntimeException if an error occurs while operator FileOutputStream<\/p>\n<p>*\/<\/p>\n<p>public static boolean copyFile(String sourceFilePath, String destFilePath) {<br \/>\n  <!-- --><\/p>\n<p>InputStream inputStream = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>inputStream = new FileInputStream(sourceFilePath);<\/p>\n<p>} catch (FileNotFoundException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"FileNotFoundException occurred. \", e);<\/p>\n<p>}<\/p>\n<p>return writeFile(destFilePath, inputStream);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* read file to string list, a element of list is a line<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @param charsetName The name of a supported {@link java.nio.charset.Charset charset<code>}<\/code><\/p>\n<p>* @return if file not exist, return null, else return content of file<\/p>\n<p>* @throws RuntimeException if an error occurs while operator BufferedReader<\/p>\n<p>*\/<\/p>\n<p>public static List readFileToList(String filePath, String charsetName) {<br \/>\n  <!-- --><\/p>\n<p>File file = new File(filePath);<\/p>\n<p>List fileContent = new ArrayList();<\/p>\n<p>if (file == null || !file.isFile()) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>BufferedReader reader = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);<\/p>\n<p>reader = new BufferedReader(is);<\/p>\n<p>String line = null;<\/p>\n<p>while ((line = reader.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>fileContent.add(line);<\/p>\n<p>}<\/p>\n<p>return fileContent;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>throw new RuntimeException(\"IOException occurred. \", e);<\/p>\n<p>} finally {<br \/>\n  <!-- --><\/p>\n<p>IOUtils.close(reader);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get file name from path, not include suffix<\/p>\n<p>*<\/p>\n<p>* <\/p>\n<pre class=\"language-java prettyprint linenums\"><\/pre>\n<p>* getFileNameWithoutExtension(null) = null<\/p>\n<p>* getFileNameWithoutExtension(\"\") = \"\"<\/p>\n<p>* getFileNameWithoutExtension(\" \") = \" \"<\/p>\n<p>* getFileNameWithoutExtension(\"abc\") = \"abc\"<\/p>\n<p>* getFileNameWithoutExtension(\"a.mp\") = \"a\"<\/p>\n<p>* getFileNameWithoutExtension(\"a.b.rmvb\") = \"a.b\"<\/p>\n<p>* getFileNameWithoutExtension(\"c:\\\\\") = \"\"<\/p>\n<p>* getFileNameWithoutExtension(\"c:\\\\a\") = \"a\"<\/p>\n<p>* getFileNameWithoutExtension(\"c:\\\\a.b\") = \"a\"<\/p>\n<p>* getFileNameWithoutExtension(\"c:a.txt\\\\a\") = \"a\"<\/p>\n<p>* getFileNameWithoutExtension(\"\/home\/admin\") = \"admin\"<\/p>\n<p>* getFileNameWithoutExtension(\"\/home\/admin\/a.txt\/b.mp\") = \"b\"<\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return file name from path, not include suffix<\/p>\n<p>* @see<\/p>\n<p>*\/<\/p>\n<p>public static String getFileNameWithoutExtension(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isEmpty(filePath)) {<br \/>\n  <!-- --><\/p>\n<p>return filePath;<\/p>\n<p>}<\/p>\n<p>int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR);<\/p>\n<p>int filePosi = filePath.lastIndexOf(File.separator);<\/p>\n<p>if (filePosi == -) {<br \/>\n  <!-- --><\/p>\n<p>return (extenPosi == - ? filePath : filePath.substring(, extenPosi));<\/p>\n<p>}<\/p>\n<p>if (extenPosi == -) {<br \/>\n  <!-- --><\/p>\n<p>return filePath.substring(filePosi + );<\/p>\n<p>}<\/p>\n<p>return (filePosi &lt; extenPosi ? filePath.substring(filePosi + , extenPosi) : filePath.substring(filePosi + ));<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get file name from path, include suffix<\/p>\n<p>*<\/p>\n<p>* <\/p>\n<pre class=\"language-java prettyprint linenums\"><\/pre>\n<p>* getFileName(null) = null<\/p>\n<p>* getFileName(\"\") = \"\"<\/p>\n<p>* getFileName(\" \") = \" \"<\/p>\n<p>* getFileName(\"a.mp\") = \"a.mp\"<\/p>\n<p>* getFileName(\"a.b.rmvb\") = \"a.b.rmvb\"<\/p>\n<p>* getFileName(\"abc\") = \"abc\"<\/p>\n<p>* getFileName(\"c:\\\\\") = \"\"<\/p>\n<p>* getFileName(\"c:\\\\a\") = \"a\"<\/p>\n<p>* getFileName(\"c:\\\\a.b\") = \"a.b\"<\/p>\n<p>* getFileName(\"c:a.txt\\\\a\") = \"a\"<\/p>\n<p>* getFileName(\"\/home\/admin\") = \"admin\"<\/p>\n<p>* getFileName(\"\/home\/admin\/a.txt\/b.mp\") = \"b.mp\"<\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return file name from path, include suffix<\/p>\n<p>*\/<\/p>\n<p>public static String getFileName(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isEmpty(filePath)) {<br \/>\n  <!-- --><\/p>\n<p>return filePath;<\/p>\n<p>}<\/p>\n<p>int filePosi = filePath.lastIndexOf(File.separator);<\/p>\n<p>return (filePosi == -) ? filePath : filePath.substring(filePosi + );<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get folder name from path<\/p>\n<p>*<\/p>\n<p>* <\/p>\n<pre class=\"language-java prettyprint linenums\"><\/pre>\n<p>* getFolderName(null) = null<\/p>\n<p>* getFolderName(\"\") = \"\"<\/p>\n<p>* getFolderName(\" \") = \"\"<\/p>\n<p>* getFolderName(\"a.mp\") = \"\"<\/p>\n<p>* getFolderName(\"a.b.rmvb\") = \"\"<\/p>\n<p>* getFolderName(\"abc\") = \"\"<\/p>\n<p>* getFolderName(\"c:\\\\\") = \"c:\"<\/p>\n<p>* getFolderName(\"c:\\\\a\") = \"c:\"<\/p>\n<p>* getFolderName(\"c:\\\\a.b\") = \"c:\"<\/p>\n<p>* getFolderName(\"c:a.txt\\\\a\") = \"c:a.txt\"<\/p>\n<p>* getFolderName(\"c:a\\\\b\\\\c\\\\d.txt\") = \"c:a\\\\b\\\\c\"<\/p>\n<p>* getFolderName(\"\/home\/admin\") = \"\/home\"<\/p>\n<p>* getFolderName(\"\/home\/admin\/a.txt\/b.mp\") = \"\/home\/admin\/a.txt\"<\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getFolderName(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isEmpty(filePath)) {<br \/>\n  <!-- --><\/p>\n<p>return filePath;<\/p>\n<p>}<\/p>\n<p>int filePosi = filePath.lastIndexOf(File.separator);<\/p>\n<p>return (filePosi == -) ? \"\" : filePath.substring(, filePosi);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get suffix of file from path<\/p>\n<p>*<\/p>\n<p>* <\/p>\n<pre class=\"language-java prettyprint linenums\"><\/pre>\n<p>* getFileExtension(null) = \"\"<\/p>\n<p>* getFileExtension(\"\") = \"\"<\/p>\n<p>* getFileExtension(\" \") = \" \"<\/p>\n<p>* getFileExtension(\"a.mp\") = \"mp\"<\/p>\n<p>* getFileExtension(\"a.b.rmvb\") = \"rmvb\"<\/p>\n<p>* getFileExtension(\"abc\") = \"\"<\/p>\n<p>* getFileExtension(\"c:\\\\\") = \"\"<\/p>\n<p>* getFileExtension(\"c:\\\\a\") = \"\"<\/p>\n<p>* getFileExtension(\"c:\\\\a.b\") = \"b\"<\/p>\n<p>* getFileExtension(\"c:a.txt\\\\a\") = \"\"<\/p>\n<p>* getFileExtension(\"\/home\/admin\") = \"\"<\/p>\n<p>* getFileExtension(\"\/home\/admin\/a.txt\/b\") = \"\"<\/p>\n<p>* getFileExtension(\"\/home\/admin\/a.txt\/b.mp\") = \"mp\"<\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String getFileExtension(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isBlank(filePath)) {<br \/>\n  <!-- --><\/p>\n<p>return filePath;<\/p>\n<p>}<\/p>\n<p>int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR);<\/p>\n<p>int filePosi = filePath.lastIndexOf(File.separator);<\/p>\n<p>if (extenPosi == -) {<br \/>\n  <!-- --><\/p>\n<p>return \"\";<\/p>\n<p>}<\/p>\n<p>return (filePosi &gt;= extenPosi) ? \"\" : filePath.substring(extenPosi + );<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* Creates the directory named by the trailing filename of this file, including the complete directory path required<\/p>\n<p>* to create this directory. <\/p>\n<p>* <\/p>\n<p>* <\/p>\n<p>* <strong>Attentions:<\/strong><\/p>\n<p>* <\/p>\n<p>makeDirs(\"C:\\\\Users\\\\Trinea\") can only create users folder <\/p>\n<p>* <\/p>\n<p>makeFolder(\"C:\\\\Users\\\\Trinea\\\\\") can create Trinea folder <\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return true if the necessary directories have been created or the target directory already exists, false one of<\/p>\n<p>* the directories can not be created.<\/p>\n<p>* <\/p>\n<p>* <\/p>\n<p>if {@link FileUtils#getFolderName(String)} return null, return false <\/p>\n<p>* <\/p>\n<p>if target directory already exists, return true <\/p>\n<p>* <\/p>\n<p>return {@link java.io.File#makeFolder} <\/p>\n<p>* <\/p>\n<p>*\/<\/p>\n<p>public static boolean makeDirs(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>String folderName = getFolderName(filePath);<\/p>\n<p>if (StringUtils.isEmpty(folderName)) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>File folder = new File(folderName);<\/p>\n<p>return (folder.exists() &amp;&amp; folder.isDirectory()) ? true : folder.mkdirs();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* @param filePath<\/p>\n<p>* @return<\/p>\n<p>* @see #makeDirs(String)<\/p>\n<p>*\/<\/p>\n<p>public static boolean makeFolders(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>return makeDirs(filePath);<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* Indicates if this file represents a file on the underlying file system.<\/p>\n<p>*<\/p>\n<p>* @param filePath<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean isFileExist(String filePath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isBlank(filePath)) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>File file = new File(filePath);<\/p>\n<p>return (file.exists() &amp;&amp; file.isFile());<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* Indicates if this file represents a directory on the underlying file system.<\/p>\n<p>*<\/p>\n<p>* @param directoryPath<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean isFolderExist(String directoryPath) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isBlank(directoryPath)) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>File dire = new File(directoryPath);<\/p>\n<p>return (dire.exists() &amp;&amp; dire.isDirectory());<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* delete file or directory<\/p>\n<p>* <\/p>\n<p>* <\/p>\n<p>if path is null or empty, return true <\/p>\n<p>* <\/p>\n<p>if path not exist, return true <\/p>\n<p>* <\/p>\n<p>if path exist, delete recursion. return true <\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param path<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static boolean deleteFile(String path) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isBlank(path)) {<br \/>\n  <!-- --><\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>File file = new File(path);<\/p>\n<p>if (!file.exists()) {<br \/>\n  <!-- --><\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>if (file.isFile()) {<br \/>\n  <!-- --><\/p>\n<p>return file.delete();<\/p>\n<p>}<\/p>\n<p>if (!file.isDirectory()) {<br \/>\n  <!-- --><\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>for (File f : file.listFiles()) {<br \/>\n  <!-- --><\/p>\n<p>if (f.isFile()) {<br \/>\n  <!-- --><\/p>\n<p>f.delete();<\/p>\n<p>} else if (f.isDirectory()) {<br \/>\n  <!-- --><\/p>\n<p>deleteFile(f.getAbsolutePath());<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>return file.delete();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get file size<\/p>\n<p>* <\/p>\n<p>* <\/p>\n<p>if path is null or empty, return - <\/p>\n<p>* <\/p>\n<p>if path exist and it is a file, return file size, else return - <\/p>\n<p>* <\/p>\n<p>*<\/p>\n<p>* @param path<\/p>\n<p>* @return returns the length of this file in bytes. returns - if the file does not exist.<\/p>\n<p>*\/<\/p>\n<p>public static long getFileSize(String path) {<br \/>\n  <!-- --><\/p>\n<p>if (StringUtils.isBlank(path)) {<br \/>\n  <!-- --><\/p>\n<p>return -;<\/p>\n<p>}<\/p>\n<p>File file = new File(path);<\/p>\n<p>return (file.exists() &amp;&amp; file.isFile() ? file.length() : -);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u4e09\u3001assets\u548craw\u8d44\u6e90\u5de5\u5177\u7c7b ResourceUtils.java<\/p>\n<p>public class ResourceUtils {<br \/>\n  <!-- --><\/p>\n<p>private ResourceUtils() {<br \/>\n  <!-- --><\/p>\n<p>throw new AssertionError();<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get an asset using ACCESS_STREAMING mode. This provides access to files that have been bundled with an<\/p>\n<p>* application as assets -- that is, files placed in to the \"assets\" directory.<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param fileName The name of the asset to open. This name can be hierarchical.<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String geFileFromAssets(Context context, String fileName) {<br \/>\n  <!-- --><\/p>\n<p>if (context == null || StringUtils.isEmpty(fileName)) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>StringBuilder s = new StringBuilder(\"\");<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader in = new InputStreamReader(context.getResources().getAssets().open(fileName));<\/p>\n<p>BufferedReader br = new BufferedReader(in);<\/p>\n<p>String line;<\/p>\n<p>while ((line = br.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>s.append(line);<\/p>\n<p>}<\/p>\n<p>return s.toString();<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* get content from a raw resource. This can only be used with resources whose value is the name of an asset files<\/p>\n<p>* -- that is, it can be used to open drawable, sound, and raw resources; it will fail on string and color<\/p>\n<p>* resources.<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param resId The resource identifier to open, as generated by the appt tool.<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static String geFileFromRaw(Context context, int resId) {<br \/>\n  <!-- --><\/p>\n<p>if (context == null) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>StringBuilder s = new StringBuilder();<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader in = new InputStreamReader(context.getResources().openRawResource(resId));<\/p>\n<p>BufferedReader br = new BufferedReader(in);<\/p>\n<p>String line;<\/p>\n<p>while ((line = br.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>s.append(line);<\/p>\n<p>}<\/p>\n<p>return s.toString();<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* same to {@link ResourceUtils#geFileFromAssets(Context, String)}, but return type is List<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param fileName<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static List geFileToListFromAssets(Context context, String fileName) {<br \/>\n  <!-- --><\/p>\n<p>if (context == null || StringUtils.isEmpty(fileName)) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>List fileContent = new ArrayList();<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader in = new InputStreamReader(context.getResources().getAssets().open(fileName));<\/p>\n<p>BufferedReader br = new BufferedReader(in);<\/p>\n<p>String line;<\/p>\n<p>while ((line = br.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>fileContent.add(line);<\/p>\n<p>}<\/p>\n<p>br.close();<\/p>\n<p>return fileContent;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/**<\/p>\n<p>* same to {@link ResourceUtils#geFileFromRaw(Context, int)}, but return type is List<\/p>\n<p>*<\/p>\n<p>* @param context<\/p>\n<p>* @param resId<\/p>\n<p>* @return<\/p>\n<p>*\/<\/p>\n<p>public static List geFileToListFromRaw(Context context, int resId) {<br \/>\n  <!-- --><\/p>\n<p>if (context == null) {<br \/>\n  <!-- --><\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>List fileContent = new ArrayList();<\/p>\n<p>BufferedReader reader = null;<\/p>\n<p>try {<br \/>\n  <!-- --><\/p>\n<p>InputStreamReader in = new InputStreamReader(context.getResources().openRawResource(resId));<\/p>\n<p>reader = new BufferedReader(in);<\/p>\n<p>String line = null;<\/p>\n<p>while ((line = reader.readLine()) != null) {<br \/>\n  <!-- --><\/p>\n<p>fileContent.add(line);<\/p>\n<p>}<\/p>\n<p>reader.close();<\/p>\n<p>return fileContent;<\/p>\n<p>} catch (IOException e) {<br \/>\n  <!-- --><\/p>\n<p>e.printStackTrace();<\/p>\n<p>return null;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u56db\u3001\u5355\u4f8b\u5de5\u5177\u7c7b SingletonUtils.java<\/p>\n<p>public abstract class SingletonUtils {<br \/>\n  <!-- --><\/p>\n<p>private T instance;<\/p>\n<p>protected abstract T newInstance();<\/p>\n<p>public final T getInstance() {<br \/>\n  <!-- --><\/p>\n<p>if (instance == null) {<br \/>\n  <!-- --><\/p>\n<p>synchronized (SingletonUtils.class) {<br \/>\n  <!-- --><\/p>\n<p>if (instance == null) {<br \/>\n  <!-- --><\/p>\n<p>instance = newInstance();<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>return instance;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\u5341\u4e94\u3001\u6570\u636e\u5e93\u5de5\u5177\u7c7b SqliteUtils.java<\/p>\n<p>public class SqliteUtils {<br \/>\n  <!-- --><\/p>\n<p>private static volatile SqliteUtils instance;<\/p>\n<p>private DbHelper dbHelper;<\/p>\n<p>private SQLiteDatabase db;<\/p>\n<p>private SqliteUtils(Context context) {<br \/>\n  <!-- --><\/p>\n<p>dbHelper = new DbHelper(context);<\/p>\n<p>db = dbHelper.getWritableDatabase();<\/p>\n<p>}<\/p>\n<p>public static SqliteUtils getInstance(Context context) {<br \/>\n  <!-- --><\/p>\n<p>if (instance == null) {<br \/>\n  <!-- --><\/p>\n<p>synchronized (SqliteUtils.class) {<br \/>\n  <!-- --><\/p>\n<p>if (instance == null) {<br \/>\n  <!-- --><\/p>\n<p>instance = new SqliteUtils(context);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>return instance;<\/p>\n<p>}<\/p>\n<p>public SQLiteDatabase getDb() {<br \/>\n  <!-- --><\/p>\n<p>return db;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"android app\u5feb\u901f\u5f00\u53d1_android app\u5f00\u53d1\u5de5\u5177\u4e00\u3001\u65e5\u5fd7\u5de5\u5177\u7c7bLog.javapublicclassL{privateL(){\/*\u4e0d\u53ef\u88ab\u5b9e\u4f8b\u5316*\/thrownewUnsuppor...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8170"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8170"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8170\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}