从本地读取json文件
2014-11-10 11:05
405 查看
1.拿到json文件
File file=new File(Constant.SDPATH+json);
String json=FileUtil.getFileString(file);
2.读取解析
public static String getFileString(File file) {
try {
if (!file.exists())
return null;
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
StringBuilder stringBuilder = new StringBuilder();
for (String line = reader.readLine(); line != null; line = reader
.readLine()) {
stringBuilder.append(line);
}
reader.close();
return stringBuilder.toString().trim();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
File file=new File(Constant.SDPATH+json);
String json=FileUtil.getFileString(file);
2.读取解析
public static String getFileString(File file) {
try {
if (!file.exists())
return null;
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
StringBuilder stringBuilder = new StringBuilder();
for (String line = reader.readLine(); line != null; line = reader
.readLine()) {
stringBuilder.append(line);
}
reader.close();
return stringBuilder.toString().trim();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
相关文章推荐
- iOS国家城市选择器 读取本地json文件
- android 读取本地json文件 解决显示乱码显示
- 读取本地Json文件
- ios本地文件内容读取,.json .plist 文件读写
- 网页端中将表格数据和JSON数据读取(导出)到本地的excel和csv文件中
- IOS 读取本地的Json/plist 文件
- 从本地JSON文件中读取数据
- Android中读取asset路径下本地json文件
- 不开webServer让chrome能读取本地json等文件
- 实现读取本地json格式文件并解析
- Jquery $.ajax $.getJson读取本地文件的问题-Received an invalid response not allowed access(echarts本地测试地图包)
- 关于JQuery加载本地JSON文件无法读取(权限不足的)解决
- ios-本地项目下 json文件的读取
- 读取本地json文件
- 关于chrome浏览器下使用js读取本地json文件时提示“Origin null is not allowed by Access-Control-Allow-Origin”问题
- 如何读取一个本地Json文件并查询该文件展示其内容
- android 读取本地的json文件
- java 读取本地的json文件
- Android读取本地json文件的方法(解决显示乱码问题)
- JQuery读取本地Json文件