Java examples for File Path IO:File Operation
Reading text file with the readAllLines() Method
import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; public class Main { public static void main(String[] args) { Path wiki_path = Paths.get("C:/folder1/wiki", "wiki.txt"); Charset charset = Charset.forName("ISO-8859-1"); try {/*from ww w.j a v a 2s . c o m*/ List<String> lines = Files.readAllLines(wiki_path, charset); for (String line : lines) { System.out.println(line); } } catch (IOException e) { System.out.println(e); } } }
Files.readAllLines recognizes the following as line terminators: