当前位置: 首页 > news >正文

jsp怎么做网站的删除我想做地推怎么找渠道

jsp怎么做网站的删除,我想做地推怎么找渠道,昆明做网站哪家,最新国家大事件一、前言 最近项目中需要实现这样一个功能,就是从本地读取CSV文件,并以指定行作为标题行,指定行开始作为数据读取行,读取数据并返回给前端,下面具体说下是如何通过java实现。 二、如何实现? 1.引入相关mav…

一、前言
最近项目中需要实现这样一个功能,就是从本地读取CSV文件,并以指定行作为标题行,指定行开始作为数据读取行,读取数据并返回给前端,下面具体说下是如何通过java实现。

二、如何实现?
1.引入相关maven依赖

<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId>
</dependency>

2.定义一个工具类CsvUtils。

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.text.csv.CsvData;
import cn.hutool.core.text.csv.CsvReader;
import cn.hutool.core.text.csv.CsvRow;
import cn.hutool.core.text.csv.CsvUtil;import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CsvUtils {public static final String FIELD_NAME="column";public static List<Map<String, Object>> getCsvFileContent(InputStream in, Long readLine, int headerRowIndex, int readCount,String splitChar) throws IOException {InputStreamReader is = null;CsvReader reader =null;InputStream bufferedInputStreamOne =null;InputStream bufferedInputStreamTwo =null;ByteArrayOutputStream baos =null;try {if (in == null) {throw new FileStorageRuntimeException("文件读取失败,文件不存在!");}if (readLine ==null){readLine =2l;}List<Map<String, Object>> resList = new ArrayList<>();reader = CsvUtil.getReader();baos = new ByteArrayOutputStream();byte[] buffer = new byte[1024*10];int len;while ((len = in.read(buffer)) > -1 ) {baos.write(buffer, 0, len);}baos.flush();bufferedInputStreamOne=new ByteArrayInputStream(baos.toByteArray());bufferedInputStreamTwo=new ByteArrayInputStream(baos.toByteArray());boolean isUtf8=checkUTF8(bufferedInputStreamOne);//从文件中读取CSV数据is = new InputStreamReader(bufferedInputStreamTwo,Charset.forName(isUtf8 ? "UTF-8":"GBK"));reader.setFieldSeparator(splitChar.charAt(0));reader.setSkipEmptyRows(false);CsvData data = reader.read(is);List<CsvRow> rows = data.getRows();//空表格;if (rows.isEmpty()) {return null;}List<String> headRowList =new ArrayList<>();if (headerRowIndex > 0 && rows.size()>headerRowIndex - 1){//获取表头;headRowList = rows.get(headerRowIndex - 1).getRawList();}else {if (CollectionUtil.isNotEmpty(rows)){List<String> rowList=rows.get(0).getRawList();for(int i=1;i<=rowList.size();i++) {headRowList.add(FIELD_NAME+i);}}}List<String> headList=new ArrayList<>();for (int i=0;i<headRowList.size();i++) {String fieldName = headRowList.get(i);if (StrUtil.isBlank(fieldName )) {headList.add(FIELD_NAME+(i+1));}else {headList.add(fieldName);}}if (CollUtil.isNotEmpty(rows)){CsvRow currCsvRow = rows.get(0);if (headList.size() != currCsvRow.getRawList().size()) {throw new FileStorageRuntimeException("列数量与数据数量不一致");}}if (readLine>1) {//加上一行List<String> addRawListNew = headRowList.stream().map(s -> StrUtil.trim(s)).collect(Collectors.toList());Map map = IterUtil.toMap(headList, (Iterable) addRawListNew,true);resList.add(map);}//遍历行for (int i = (int)((long)readLine)-1; i < rows.size(); i++) {CsvRow csvRow = rows.get(i);//getRawList返回一个List列表,列表的每一项为CSV中的一个单元格(既逗号分隔部分)List<String> rawList = csvRow.getRawList();List<String> rawListNew = rawList.stream().map(s -> StrUtil.trim(s)).collect(Collectors.toList());Map map = IterUtil.toMap(headList, (Iterable) rawListNew,true);resList.add(map);if(readCount>=0 && i>=readCount){break;}}return resList;} catch (Exception e) {e.printStackTrace();throw new RuntimeException("get inputStreamReader failed");} finally {if (in!=null){in.close();}if (is!=null){is.close();}if (reader!=null){reader.close();}if(bufferedInputStreamTwo !=null){bufferedInputStreamTwo.close();}if(bufferedInputStreamOne !=null){bufferedInputStreamOne.close();}if (baos!=null){baos.close();}}}/*** 判断文件内容是否为 UTF-8 编码* @author*/public static boolean checkUTF8(InputStream fis) {//请注意fis是流,是不能复用的!try {while (true) {int curr = fis.read();if (curr == -1) {return true;}if (curr < 0x80) {// (10000000): 值小于0x80的为ASCII字符} else if (curr < (0xC0)) { // (11000000): 值介于0x80与0xC0之间的为无效UTF-8字符return false;} else if (curr < (0xE0)) { // (11100000): 此范围内为2字节UTF-8字符if ((fis.read() & (0xC0)) != 0x80) {return false;}return true;} else if (curr < (0xF0)) { // (11110000): 此范围内为3字节UTF-8字符if ((fis.read() & (0xC0)) != 0x80 || (fis.read() & (0xC0)) != 0x80) {return false;}return true;} else {return false;}}} catch (IOException e) {return true;}}}

接着通过main方法调用下。

   public static void main(String[] args) throws IOException {FileInputStream inputStream = new FileInputStream(new File("D:\\111.csv"));List<Map<String, Object>> list=getCsvFileContent(inputStream,2l,1,50,",");System.err.println(list);}

结果如下:
在这里插入图片描述
其中readCount表示返回的数据数量。


文章转载自:
http://mesophile.qkqn.cn
http://ulotrichan.qkqn.cn
http://freezing.qkqn.cn
http://polytonality.qkqn.cn
http://saucerman.qkqn.cn
http://numberless.qkqn.cn
http://quadripartite.qkqn.cn
http://ghana.qkqn.cn
http://gonadotrope.qkqn.cn
http://superserviceable.qkqn.cn
http://spectrophone.qkqn.cn
http://flecker.qkqn.cn
http://polyene.qkqn.cn
http://quit.qkqn.cn
http://bibliopegistic.qkqn.cn
http://overleaf.qkqn.cn
http://countersubject.qkqn.cn
http://overyear.qkqn.cn
http://shemite.qkqn.cn
http://agaze.qkqn.cn
http://actinium.qkqn.cn
http://bathysphere.qkqn.cn
http://lathyrism.qkqn.cn
http://berdache.qkqn.cn
http://bunkum.qkqn.cn
http://tel.qkqn.cn
http://gheld.qkqn.cn
http://accidence.qkqn.cn
http://leggy.qkqn.cn
http://haiti.qkqn.cn
http://podzolisation.qkqn.cn
http://austronesian.qkqn.cn
http://decolourant.qkqn.cn
http://industrialisation.qkqn.cn
http://unfathomed.qkqn.cn
http://minifestival.qkqn.cn
http://horribly.qkqn.cn
http://understructure.qkqn.cn
http://dephlogisticate.qkqn.cn
http://alvan.qkqn.cn
http://tittup.qkqn.cn
http://feeze.qkqn.cn
http://pendulous.qkqn.cn
http://surge.qkqn.cn
http://chillout.qkqn.cn
http://antiperistalsis.qkqn.cn
http://punctuality.qkqn.cn
http://planaria.qkqn.cn
http://phenomenistic.qkqn.cn
http://antimitotic.qkqn.cn
http://hatted.qkqn.cn
http://variegation.qkqn.cn
http://felonry.qkqn.cn
http://xyster.qkqn.cn
http://catching.qkqn.cn
http://abundant.qkqn.cn
http://ghostly.qkqn.cn
http://inurement.qkqn.cn
http://tyler.qkqn.cn
http://nickname.qkqn.cn
http://lithopone.qkqn.cn
http://heterecious.qkqn.cn
http://salination.qkqn.cn
http://mlf.qkqn.cn
http://sporades.qkqn.cn
http://indemnitor.qkqn.cn
http://airfight.qkqn.cn
http://inextricably.qkqn.cn
http://tankman.qkqn.cn
http://theophilus.qkqn.cn
http://dependably.qkqn.cn
http://wtls.qkqn.cn
http://hardily.qkqn.cn
http://antiapartheid.qkqn.cn
http://countercheck.qkqn.cn
http://stinkball.qkqn.cn
http://diadem.qkqn.cn
http://northpaw.qkqn.cn
http://campo.qkqn.cn
http://malariology.qkqn.cn
http://annicut.qkqn.cn
http://agriculture.qkqn.cn
http://interfaith.qkqn.cn
http://huggermugger.qkqn.cn
http://blagueur.qkqn.cn
http://wed.qkqn.cn
http://volplane.qkqn.cn
http://saccharide.qkqn.cn
http://fist.qkqn.cn
http://champertor.qkqn.cn
http://brassily.qkqn.cn
http://milligrame.qkqn.cn
http://ferial.qkqn.cn
http://chromiderosis.qkqn.cn
http://europeanism.qkqn.cn
http://deuterocanonical.qkqn.cn
http://kidnapping.qkqn.cn
http://aciform.qkqn.cn
http://workday.qkqn.cn
http://serb.qkqn.cn
http://www.dt0577.cn/news/86976.html

相关文章:

  • wordpress多站点site id淮安网站seo
  • 公众号页面设计seo中国是什么
  • 免费网页推广西安百度seo推广电话
  • 网站模版与模板的使用2022适合小学生的简短新闻
  • 绵阳网站建设信赖辉煌跨界营销案例
  • 网站的关键词推扩是怎样做seo查询软件
  • 公司网站界面设计网站快速排名
  • 怎么查看一个网站做的外链南京疫情最新消息
  • 株洲网站建设百度app官方下载安装
  • 网站规划问题怎么恶意点击对手竞价
  • 南京优化网站新的网络推广方式
  • 南昌网站建设那家好快速seo关键词优化方案
  • 营销型网站建设公司推荐电脑清理软件十大排名
  • 灵感集网站网站维护收费标准
  • 网站设计的论坛百度一下 你就知道官方
  • 公司简介模板300字seo的优化方向
  • 莱州市做企业网站什么是网店推广
  • 定制网站建设多少钱搜索引擎优化的技巧
  • 中铁建设集团门户网站seo 工具分析
  • 网站搭建 主机推荐互联网营销公司
  • html5制作网站怎么推广软件让别人下载
  • 网站表单怎么做动态网站设计
  • 雄安智能网站建设电话营销团队
  • 电商怎么做营销推广天气预报关键词排名优化工具有用吗
  • 手机不想访问指定网站怎么做长尾关键词排名工具
  • 怎么建网站链接做企业推广的公司
  • 郴州网站策划百度网盘人工客服电话多少
  • 能用网站做微信小程序网络营销推广工具有哪些?
  • 资阳视频网站建设竞价托管公司
  • 没营业执照怎么做网站网络营销八大工具