/*** 方法名:saveToLocal()* 功 能:创建隐藏文件夹,保存json到本地* 参 数:无* 返回值:String*/
public static String saveToLocal() {//文件夹路径File dir = new File(Environment.getExternalStorageDirectory() + "/.TQRecorderConfig/jsonConfig/");//文件名String fileName = "config.json";try {//文件夹不存在和传入的value值为1时,才允许进入创建if (!dir.exists()) {//创建文件夹dir.mkdirs();JsonObject jsonObject = new JsonObject();jsonObject.addProperty("id", 0);jsonObject.addProperty("name", "apkName");jsonObject.addProperty("value", 0);String json = jsonObject.toString();File file = new File(dir, fileName);OutputStream out = new FileOutputStream(file);out.write(json.getBytes());out.close();XLog.i("RecordApp", "保存Config成功 path:" + file.getPath());return file.getPath();} else {XLog.i("RecordApp", "Config已经存在 path:" + dir + "/" + fileName);return dir + "/" + fileName;}} catch (Exception e) {e.printStackTrace();XLog.i("RecordApp", "Config保存失败");}return "";
}/*** 方法名:readJsonFile(String filePath)* 功 能:从本地读取json* 参 数:String filePath* 返回值:String*/
public static String readJsonFile(String filePath) {StringBuilder sb = new StringBuilder();try {File file = new File(filePath);InputStream in = null;in = new FileInputStream(file);int tempbyte;while ((tempbyte = in.read()) != -1) {sb.append((char) tempbyte);}in.close();} catch (Exception e) {e.printStackTrace();}return sb.toString();
}
详细解决方案
103.android 简单的保存、读取本地json文件
热度:77 发布时间:2024-01-24 05:26:34.0
相关解决方案
- json 解析有关问题
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- 请教哪里可以上到 struts2-json-plugin-2.1.8的源文件
- java+jquery easy ui + json + struts分页例子
- ssh json jar 有关问题
- json 有关问题
- jquery.load(*json) 解析不已。求帮忙
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android RadioButton如何设置默认选中
- android 怎么重新设置锚点
- android 图片对象获取的有关问题
- android 关于服务连接的疑义
- android 怎么实现对view的放大和缩小
- json 转成 string解决办法
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》
- android UI线程与AsyncTask的有关问题
- android(java) 中文乱码的有关问题
- MVC(Json) 出现提示上载
- HttpWebRequest post json 数据,接受应该怎么获取啊
- jqGrid json 不显示数据,该如何处理
- JQUERY AJAX JSON 有关问题 求大侠指点
- json[0].CodeID值为undefined解决方法
- android 动态设立控件高度
- Android test project 编译方法