반응형
public static void writeFile(String fileName, String path, List<Map<String, Object>> list) {
try {
String filePath = path + fileName;
File destdir = new File(path);
if (!destdir.exists()) {
destdir.mkdirs();
}
OutputStream output = new FileOutputStream(filePath);
StringBuffer sb = new StringBuffer();
JSONArray arrayStr = convertListToJson(list);
for(int i = 0; i< arrayStr.size(); i++){
sb.append(arrayStr.get(i).toString()+"\n");
}
byte[] by = sb.toString().getBytes();
output.write(by);
} catch (Exception e) {
e.getStackTrace();
}
}
public static JSONArray convertListToJson(List<Map<String, Object>> bankCdList) {
JSONArray jsonArray = new JSONArray();
for (Map<String, Object> map : bankCdList) {
jsonArray.add(convertMapToJson(map));
}
return jsonArray;
}
반응형
'Back > Spring Java' 카테고리의 다른 글
for문(Loop) 성능 개선 - 1 (0) | 2020.04.13 |
---|---|
File객체를 이용한 파일삭제 (0) | 2020.04.01 |
No 'Access-Control-Allow-Origin' header is present on the requested resource. (CORS policy) (0) | 2020.03.02 |
CamelCase, SnakeCase Convert Function (0) | 2020.01.14 |
Class Object Entity convert to Map (0) | 2020.01.14 |