fctom1215
2020-02-12 cf7d11cec0853f903cb2ef13d18945f1ce46ddb3
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();
    }
}