Java examples for File Path IO:File Operation
The following code snippet reads the wiki.txt file using the UTF-8 charset:
import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path wiki_path = Paths.get("C:/folder1/wiki", "wiki.txt"); Charset charset = Charset.forName("UTF-8"); try (BufferedReader reader = Files.newBufferedReader(wiki_path, charset)) { String line = null;// w w w . jav a 2 s. c o m while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException e) { System.err.println(e); } } }