CsvProcessor implements FileProcessor { @Override public void importBeans(Class<?> clazz, Object[] beans, String filePath) throws IOException { List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); List<String> datas = CollectionUtil.createArrayList(beans.length + 1); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isNotEmpty(titles)) { datas.add(CsvUtil.toCsvString(titles)); } for (Object bean : beans) { datas.add(toCsvLine(list, bean)); } WriterUtil.writeLinesAndClose(filePath, datas, GBK); }  @Override void importBean(Object bean, String filePath); @Override void importBeans(Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(String[] contents, String filePath); @Override void importBeans(List<String> contents, String filePath); @Override T exportBean(Class<T> clazz, String filePath); @Override List<T> exportBeans(Class<T> clazz, String filePath); @Override void importBeans(String[] headers, Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(ListMap<String, String> headers, Class<?> clazz, Object[] beans, String filePath); @Override List<String> collectData(FileBeanInfo beanInfo); @Override void importBeans(FileBeanInfo beanInfo, String filePath); @Override ByteArray toByteArray(FileBeanInfo beanInfo); @Override ByteArray toByteArray(List<String> contents);  }
@Test public void importBeans() { List<CsvBean> list = CollectionUtil.createArrayList(); CsvBean bean = createBean("小明", 25, "自由", "某某小区"); list.add(bean); bean = createBean("小李", 28, "IT", "某某家园"); list.add(bean); bean = createBean("小红", 7, null, "父母家"); list.add(bean); bean = createBean("小王", 26, "金融", "某某别墅"); list.add(bean); try { processor.importBeans(bean.getClass(), list.toArray(new CsvBean[0]), testBeansPath); } catch (IOException e) { logger.error("", e); } }