| | |
| | | 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"; |
| | |
| | | * @param assertfileName |
| | | */ |
| | | public static void copyAssertFileToSD(Context context,String assertfileName){ |
| | | |
| | | try { |
| | | InputStream inputStream = null; |
| | | try { |
| | |
| | | } 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(); |
| | | } |
| | | } |
| | |
| | | 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(); |
| | | } |
| | | |
| | | } |