Class CsvUtil

java.lang.Object
com.sure.tool.collection.CsvUtil

public class CsvUtil extends Object
CSV 读写工具类(最小实现),支持引号包裹、引号内逗号与双引号转义,参考 Hutool 的 CsvUtil 设计。
Since:
0.1.0
Author:
suretool
  • Method Details

    • read

      public static List<List<String>> read(String csv)
      解析 CSV 字符串。
      Parameters:
      csv - CSV 内容
      Returns:
      行列表(每行为字段列表)
    • read

      public static List<List<String>> read(File file) throws IOException
      读取 CSV 文件(UTF-8)。
      Parameters:
      file - 文件
      Returns:
      行列表
      Throws:
      IOException - 读取失败
    • toCsv

      public static String toCsv(List<List<String>> rows)
      序列化为 CSV 字符串。
      Parameters:
      rows - 行列表(每行为字段列表)
      Returns:
      CSV 内容
    • write

      public static void write(File file, List<List<String>> rows) throws IOException
      写入 CSV 文件(UTF-8)。
      Parameters:
      file - 文件
      rows - 行列表
      Throws:
      IOException - 写入失败
    • read

      public static List<List<String>> read(File file, Charset charset) throws IOException
      读取 CSV 文件(指定字符集)。
      Parameters:
      file - 文件
      charset - 字符集
      Returns:
      行数据
      Throws:
      IOException - IO 异常
    • write

      public static void write(File file, List<List<String>> rows, Charset charset) throws IOException
      写入 CSV 文件(指定字符集)。
      Parameters:
      file - 文件
      rows - 行数据
      charset - 字符集
      Throws:
      IOException - IO 异常
    • read

      public static List<List<String>> read(InputStream in, Charset charset) throws IOException
      读取 CSV 输入流。
      Parameters:
      in - 输入流
      charset - 字符集
      Returns:
      行列表
      Throws:
      IOException - IO 异常
    • write

      public static void write(Writer writer, List<List<String>> rows) throws IOException
      写出 CSV 到 Writer。
      Parameters:
      writer - Writer
      rows - 行列表
      Throws:
      IOException - IO 异常