Skip to main content
Skip table of contents

iText 7 Building Blocks - Util: Utilities for the building blocks examples

csvto2dlist

JAVA
JAVA
package com.itextpdf.highlevel.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CsvTo2DList {
   
    public static final List<List<String>> convert(String src, String separator) throws IOException {
        List<List<String>> resultSet = new ArrayList<>();
        
        BufferedReader br = new BufferedReader(
            new InputStreamReader(new FileInputStream(src), "UTF8"));
        String line;
        List record;
        while ((line = br.readLine()) != null) {
            StringTokenizer tokenizer = new StringTokenizer(line, separator);
            record = new ArrayList<>();
            while (tokenizer.hasMoreTokens()) {
                record.add(tokenizer.nextToken());
            }
            resultSet.add(record);
        }
        return resultSet;
    }
    
}
C#
C#
using System;
using System.Collections.Generic;
using System.IO;
using iText.Commons.Utils;

namespace iText.Highlevel.Util {
    public class CsvTo2DList {
        public static IList<IList<String>> Convert(String src, String separator) {
            IList<IList<String>> resultSet = new List<IList<String>>();
            StreamReader sr = File.OpenText(src);
            String line;
            IList<string> record;
            while ((line = sr.ReadLine()) != null) {
                StringTokenizer tokenizer = new StringTokenizer(line, separator);
                record = new List<string>();
                while (tokenizer.HasMoreTokens()) {
                    record.Add(tokenizer.NextToken());
                }
                resultSet.Add(record);
            }
            return resultSet;
        }
    }
}




JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.