Reading columns of a delimited text file This class reads a delimited text file into String arrays on demand. Delimiter can be any regex.

Features include:


Read a single column
Read a range of columns
Read arbitrary columns by providing an array of indices, e.g. for columns 1, 3, 5, use new int[]{1, 3, 5}




import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IDEA on 17/11/14.
 */
public class Txt {
    final private String sep;
    final private Pattern pattern;
    final private String filename;
    private Supplier&lt;Stream&lt;String&gt;&gt; fileStream;
    Txt(String _filename, String _sep) throws IOException {
        sep = _sep;
        filename = _filename;
        pattern = Pattern.compile(sep);
        fileStream = () -&gt; {
            try {
                return Files.lines(Paths.get(filename), Charset.defaultCharset());
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        };
    }
    Txt(String _filename) throws IOException {
        this(_filename, "\\s+");
    }


    public String[] nthCol(int n) throws IOException {
        if(n &lt; 1) n = 1;
        final int finalN = n;
        List&lt;String&gt; colList =  fileStream.get()
                .map(line -&gt; pattern.split(line, finalN + 1)[finalN - 1])
                .collect(Collectors.toList());
        return colList.toArray(new String[colList.size()]);
    }

    public String[][] cols() throws IOException {
        List&lt;String[]&gt; colsList =  fileStream.get()
                .map(line -&gt; pattern.split(line))
                .collect(Collectors.toList());
        return colsList.toArray(new String[colsList.size()][]);
    }

    public String[][] cols(final int start, final int end) {
        if(start &gt; end || start &lt; 1) throw new IllegalArgumentException("Starting index must &lt;= ending index AND &gt;= 1");
        List&lt;String[]&gt; colsList =  fileStream.get()
                .map(line -&gt; {
                    String[] fields = pattern.split(line, end + 1);
                    // indices of col 2-4          2 3 4
                    // fields after splitting    0 1 2 3 4
                    // range of array              1     4
                    // java ending index is              exclusive
                    String[] demandedFields = Arrays.copyOfRange(fields, start-1, end);
                    return demandedFields;
                })
                .collect(Collectors.toList());
        return colsList.toArray(new String[colsList.size()][]);
    }

    public String[][] cols(int[] index) {
        Arrays.sort(index);
        final int[] finalIndex = index;
        final int start = finalIndex[0];
        final int end = finalIndex[finalIndex.length - 1];
        if(start &gt; end || start &lt; 1) throw new IllegalArgumentException("Starting index must &lt;= ending index AND &gt;= 1");
        List&lt;String[]&gt; colsList =  fileStream.get()
                .map(line -&gt; {
                    String[] fields = pattern.split(line, end + 1);
                    String[] demandedFields = new String[finalIndex.length];
                    for(int i=0; i&lt;finalIndex.length; i++) {
                        demandedFields[i] = fields[finalIndex[i]-1];
                    }
                    return demandedFields;
                })
                .collect(Collectors.toList());

        return colsList.toArray(new String[colsList.size()][]);
    }
}
General Remarks
The code checks incoming parameters, and throws an IllegalArgumentException when they are out of bounds (except nthCol; see later).  This is a good thing.  It would be even better if you could include the faulty indices in the error message so that I don't have to pop out the debugger. ;-)
The class seems to work with 1-based indices rather than 0-based, the latter being more common in Java[1].  As you commented about this within your code (but not in your public documentation), you've felt there's a mismatch; it may be better to use 0-based indices for consistency with the rest of the JDK.
You're going through hoops to work with arrays in the public interface while using streams and collections behind the scenes.  Consider returning lists instead of arrays, or maybe even streams if you're so inclined.
Constructors
Character encodings are important, too important to force the default encoding on your users, for any definition of 'default encoding'.  Many of the classes and methods deprecated in java.io were so because they assumed about encodings, which I've seen lead to subtle but no less spectacular breakage.[2]  Allow/force your users to specify the encoding.  If they make it be this fangled default encoding, then on their heads be it.  (A simular argument could be made for Paths.get.)
For your class, it doesn't matter how it gets its stream of strings, as long as it gets it.  Make this clear in your constructor:
Txt(Supplier&lt;? extends Stream&lt;String&gt;&gt; stream, Pattern delimiter) {
    this.stream = stream;
    this.delimiter = delimiter;
}

No fuss about encodings, file paths, IOExceptions, invalid patterns...  Just the bare needs to function.  Any other constructors or static factory methods you desire are then for convenience, and should delegate to this one.
Specifics
nthCol(int) breaks with the other methods in that it tries to fix an erroneous input parameter.  This leads to the oddness of nthCol(0) succeeding but cols(0, 0) failing.  Consistency is king in library usage: nthCol should fail, or cols should succeed.[3]
[!] cols(int[]) changes the contents of the incoming array.  You don't really need to sort this array, anyway: I'd consider it a feature if the columns returned are in the same order that I requested them.
Txt is not a very descriptive name. ;-)  Consider names such as LineSplitter or TextTable.

[1] Oh, how sweetly I loathe you, java.sql, for your 1-based indexing.
[2] Fixed record length + multi-byte encoding + JNI.  It was glorious.
[3] Personally, I lean towards &quot;fail early, fail hard,&quot; (i.e. throw) but this depends on your intended audience.