You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
Java

package com.docus.bgts.utils;
import java.io.*;
/**
* json
*/
public class JsonUtils {
/**
* json
* @param fileNamejson
* @return
*/
public static String readJsonFile(String fileName) {
String jsonStr = "";
Reader reader=null;
FileReader fileReader=null;
try {
File jsonFile = new File(fileName);
fileReader = new FileReader(jsonFile);
reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
return jsonStr;
} catch (IOException e) {
e.printStackTrace();
return null;
}finally {
try {
reader.close();
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}