java读取tsv文件

2021-02-11 07:17

阅读:639

标签:exception   set   return   reader   cti   replace   ++   ack   cat   

import com.univocity.parsers.tsv.TsvParser;
import com.univocity.parsers.tsv.TsvParserSettings;
import org.springframework.util.ClassUtils;
public class StringCompareUtil {
public static Object readTsv(String url) { System.out.println(new java.util.Date().toString()); List list = new ArrayList(); try { // 创建tsv解析器settings配置对象 TsvParserSettings settings = new TsvParserSettings(); settings.getFormat().setLineSeparator("\n"); TsvParser parser = new TsvParser(settings); DataInputStream in = new DataInputStream(new FileInputStream(new File(url))); BufferedReader br = new BufferedReader(new InputStreamReader(in, "GBK"));//这里如果csv文件编码格式是utf-8,改成utf-8即可 List allRows = parser.parseAll(br); for (int i = 1; i //忽略第一行 Map map = new HashMap(); map.put("LATITUDE", (allRows.get(i)[3].trim()).replaceAll("\"", "")); map.put("LONGITUDE", (allRows.get(i)[4].trim()).replaceAll("\"", "")); map.put("NAMEPATH", (allRows.get(i)[5].trim()).replaceAll("\"", "")); System.out.println(Arrays.asList(allRows.get(i))); list.add(map); } } catch (Exception e) { e.printStackTrace(); } return list; } }
 
        dependency>
            groupId>com.univocitygroupId>
            artifactId>univocity-parsersartifactId>
            version>2.6.1version>
            type>jartype>
        dependency>

 

java读取tsv文件

标签:exception   set   return   reader   cti   replace   ++   ack   cat   

原文地址:https://www.cnblogs.com/tongsi/p/12737157.html


评论


亲,登录后才可以留言!