Java Text File Read by Charset readLines(String path, Charset charset)

Here you can find the source of readLines(String path, Charset charset)

Description

read lines from file

License

Apache License

Parameter

Parameter Description
path path to file
charset encoding of file

Exception

Parameter Description
IOException an exception

Return

list of lines from file

Declaration

public static List<String> readLines(String path, Charset charset) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

import java.util.List;

public class Main {
    /**/*ww  w.  java2s  .c o  m*/
     * read lines from file
     *
     * @param path
     *            path to file
     * @param charset
     *            encoding of file
     *
     * @throws IOException
     *
     * @return list of lines from file
     */
    public static List<String> readLines(String path, Charset charset) throws IOException {
        if (!(new File(path)).exists()) {
            throw new FileNotFoundException("Couldnt find file: " + path);
        }

        return Files.readAllLines(Paths.get(path), charset);
    }
}

Related

  1. readLineFromStream(InputStream is, StringBuffer buffer, CharsetDecoder decoder)
  2. readLines(InputStream in, Charset cs)
  3. readLines(InputStream input, Charset charset)
  4. readLines(InputStream is, CharsetDecoder decoder)
  5. readLines(String filePath, Charset charset)
  6. readNextWord(BufferedInputStream in, Charset cs)
  7. readStreamAsString(final InputStream iStream, Charset iCharset)
  8. readStreamToString(InputStream stream, Charset encoding)
  9. readString(DataInput input, int length, Charset charset)