java读取tsv文件


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 < allRows.size(); 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>