Here you can find the source of readLines(String path, Charset charset)
Parameter | Description |
---|---|
path | path to file |
charset | encoding of file |
Parameter | Description |
---|---|
IOException | an exception |
public static List<String> readLines(String path, Charset charset) throws IOException
//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); } }