
工具类方法:ReadTextUtil
package com.dc.health.platform.common.utils; import com.alibaba.fastjson.JSONObject; import java.util.ArrayList;
import java.util.List; public class ReadTextUtil { public static JSONObject ReadTextToJson(String path) {
if (path == null || "".equals(path))
return null;
List<JSONObject> jsObjectList = new ArrayList<>();
List<String> flist = SSHUtil.execCom("cat " + path);
if (flist != null && flist.size() > 0){
for (String s : flist) {
JSONObject jsObject = new JSONObject();
String[] str = s.split("\\s+");
if (str != null && str.length > 1){
jsObject.put(str[0], str[1]);
}else if (str != null && str.length > 0){
jsObject.put(str[0], "");
}
jsObjectList.add(jsObject);
}
}
JSONObject json = new JSONObject();
json.put("data", jsObjectList);
return json;
}
}
链接linux服务器:http://www.cnblogs.com/smbin/p/7736896.html