json读写

public File writeFile(String content,String path) {
if (content == null) {
return null;
}
File file = null;
OutputStream outputStream = null;
try {
file = createSDFile(path);
outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes("GBK"));
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}

public String getLocalJson(String path) throws JSONException, IOException{
String result = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
FileInputStream inputStream = new FileInputStream(path);
int len = 0;
byte[] buffer = new byte[1024];
while((len = inputStream.read(buffer)) != -1){
              outputStream.write(buffer, 0, len);
}
outputStream.close();
inputStream.close();
byte[] data = outputStream.toByteArray();
result = new String(data,"GBK");

return result;
}

你可能感兴趣的:(json,json数据读取,json数据读写)