From cf7d11cec0853f903cb2ef13d18945f1ce46ddb3 Mon Sep 17 00:00:00 2001 From: fctom1215 <fctom1215@outlook.com> Date: 星期三, 12 二月 2020 19:47:29 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/endian11/DriveJudge --- app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java | 71 ++++++++++++++++++++++++++++++++++- 1 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java index d63b1b0..57cb041 100644 --- a/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java +++ b/app/src/main/java/safeluck/drive/evaluation/util/FileUtil.java @@ -19,6 +19,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.util.List; +import java.util.Map; + +import safeluck.drive.evaluation.bean.ExamMap; public class FileUtil { private static final String TAG = "FileUtil"; @@ -165,6 +169,7 @@ * @param assertfileName */ public static void copyAssertFileToSD(Context context,String assertfileName){ + try { InputStream inputStream = null; try { @@ -173,14 +178,16 @@ } catch (IOException e) { e.printStackTrace(); } + deleteFile(context.getPackageName()+"/",assertfileName); + OutputStream outputStream = new FileOutputStream( new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+context.getPackageName(), assertfileName)); byte[] bytes = new byte[1024]; while ((inputStream.read(bytes))>0){ outputStream.write(bytes); } - inputStream.close(); outputStream.close(); - } catch (IOException e) { + inputStream.close(); + } catch (Exception e) { e.printStackTrace(); } } @@ -226,4 +233,64 @@ return out.toByteArray(); } + + private static final String SEP2 = "|"; + + private static final String SEP3 = "="; + + private static final String SEP1 = "#"; + + public static String ListToString(List<?> list) { + StringBuffer sb = new StringBuffer(); + if (list != null && list.size() > 0) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i) == null || list.get(i) == "") { + continue; + } + // 濡傛灉鍊兼槸list绫诲瀷鍒欒皟鐢ㄨ嚜宸� + if (list.get(i) instanceof List) { + sb.append(ListToString((List<?>) list.get(i))); + sb.append(SEP1); + } else if (list.get(i) instanceof Map) { + sb.append(MapToString((Map<?, ?>) list.get(i))); + sb.append(SEP1); + } else { + sb.append(list.get(i)); + sb.append(SEP1); + } + } + } + return "L" + sb.toString(); + } + /** + * Map杞崲String + * + * @param map + * :闇�瑕佽浆鎹㈢殑Map + * @return String杞崲鍚庣殑瀛楃涓� + */ + public static String MapToString(Map<?, ?> map) { + StringBuffer sb = new StringBuffer(); + // 閬嶅巻map + for (Object obj : map.keySet()) { + if (obj == null) { + continue; + } + Object key = obj; + Object value = map.get(key); + if (value instanceof List<?>) { + sb.append(key.toString() + SEP1 + ListToString((List<?>) value)); + sb.append(SEP2); + } else if (value instanceof Map<?, ?>) { + sb.append(key.toString() + SEP1 + + MapToString((Map<?, ?>) value)); + sb.append(SEP2); + } else { + sb.append(key.toString() + SEP3 + value.toString()); + sb.append(SEP2); + } + } + return "M" + sb.toString(); + } + } -- Gitblit v1.8.0